我正在开发一个 swing 小程序,它具有带有 GridLayout 的 JPanel。
放置到此布局中的小部件的行和列对于小部件来说很重要。目前,我不保留对小部件的引用(尽管它们是 Swing 小部件的子类,因此它们很容易修改)。
在某个阶段,我需要此网格中的一个小部件来处理其相邻的小部件;也就是说,GridLayout 中其左、右、上、下的 widget 必须可供该 widget 访问。
我是否可以通过了解布局中的行号和列号来从 GridLayout 获取对这些小部件的引用?有相关的GridLayout方法吗?
(我相信 Qt GUI 框架有一个方法)
否则,我想我必须在数组中保留对小部件的引用。
谢谢
最佳答案
Am I able to get references to these widgets from the GridLayout by knowing their row and column number in the layout? Is there a relevant GridLayout method?
带有由 GridLayout 放置的 JComponent 的 JPanel(理论上任何 LayoutManager 都实现以下两个方法)
put/getClientProperty ,您可以输入,multiple this method with any additional description
关于java - 获取 Swing GridLayout 中特定行和列的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16715903/