我有 Swing 应用程序,它执行以下操作:
public void init() {
jFrame = new JFrame();
...
jFrame.add(sortingDataInputComponent.asComponent());
...
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.pack();
jFrame.setVisible(true);
jFrame.toFront();
}
有 sortingDataInputComponent 是 JPanel 与
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
其中有另一个 JPanel 与
jPanel.setLayout(new GridLayout(0,numberOfColumns));
where
private final int numberOfColumns = 3;
按下按钮时内部 jpanel 会增长:
jPanel.add(rowElement.getLabel(), insertionIndex);
jPanel.add(rowElement.getField(), insertionIndex + 1);
jPanel.add(rowElement.getDeleteButton(), insertionIndex + 2);
rowElements.add(rowElement);
jPanel.revalidate();
jPanel.repaint();
但主窗口不随 JPanel 一起增长。
它具有相同的初始大小。如何让JFrame随着内部JPanel的增长而增长?
实施Scrollable您添加行并覆盖的组件中的接口getPreferredScrollableViewportSize()如图所示here for JTable
and here for JList
。调用pack()
在封闭的Window
将导致它“调整大小以适应其子组件的首选尺寸和布局”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)