当按钮可见并且不可见时,框布局组件移动

问题描述:

JPanel panel = new JPanel(); 

panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); 

JPanel topPanel = new JPanel(new FlowLayout()); 

..... 

JPanel centrePanel = new JPanel(new FlowLayout(10, 0)); 

........ 

JScrollPane scrollPane = new JScrollPane(table); 

scrollPane.setPreferredSize(new Dimension(100, 160)); 

centrePanel.add(glListScrollPane); 

........ 

........ 


JPanel bottomPanel = new JPanel(); 

bottomPanel.setLayout(new GridLayout(0, 2)); 

...... 

........ 

panel.add(topPanel, BorderLayout.CENTER); 

panel.add(centrePanel, BorderLayout.CENTER); 

panel.add(bottomPanel, BorderLayout.CENTER); 

frame.add(panel); 

frame.add(standardButtonPanel); 


public void lockScreen(boolean editable) { 

standardButtonPanel.button1.setVisible(editable); 

...... 

} 

当进行编辑和取消编辑时。该小组正在改变其位置。 我已经使用BoxLayout,因为我希望组件有自己的尺寸,用户也可以调整屏幕的大小。 有没有其他方法?我可以在哪里解决布局问题?当按钮可见并且不可见时,框布局组件移动

而不是使用setVisible,尝试使用setEnabled,因为它剂量隐藏按钮(因此不影响用户界面),但使它使最终用户不能按下按钮。

+0

我们在整个产品中都有标准按钮和相同功能,我无法更改此功能。现在我已经试过\t \t panel.add(Box.createVerticalGlue());但它也没有帮助。 –