更新时间:2023-12-05 11:19:22
最简单的解决方案可能是使用 GridBagLayout #getConstraints(Component)
并简单地遍历所有组件,直到找到符合所需网格位置的组件...
The simplest solution might be to use GridBagLayout#getConstraints(Component)
and simply loop through all the components until you find one that matches the required grid position...
Component match = null;
GridBagLayout layout = ...
for (Component comp : getComponents()) {
GridBagConstraints gbc = layout.getConstraints(comp);
if (gbc.gridx = x && gbc.gridy = y) {
match = comp;
break;
}
}