2
我希望通過組件來劃分可用的總空間,具體取決於它們是縮小還是增長。這應該發生動態的意義;我沒有關於添加到屏幕上的組件數量的任何信息。組件應根據它們的屬性,保持自己的身高或生長:Swing + MigLayout,其他組件的動態增長和收縮
+++++++++++++++++++++++++++++++++
| +-----------------------+ |
| | don't grow | |
| +-----------------------+ |
| |
| +-----------------------+ |
| | | |
| | growy | |
| | | |
| +-----------------------+ |
| |
| +-----------------------+ |
| | don't grow | |
| +-----------------------+ |
| |
| +-----------------------+ |
| | don't grow | |
| +-----------------------+ |
| |
| +-----------------------+ |
| | | |
| | growy | |
| | | |
| +-----------------------+ |
| |
| +-----------------------+ |
| | don't grow | |
| +-----------------------+ |
+++++++++++++++++++++++++++++++++
我能夠創建以下結果:
提供的是以下SSCCE:
public class SimpleMain {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("MigLayout");
JPanel panel = new JPanel(new MigLayout("debug, flowy", "grow", "grow"));
// 1st set of textfields
panel.add(new JTextField(), "shrink, growx, top");
panel.add(new JTextField(), "grow, top");
panel.add(new JTextField(), "shrink, growx, top");
// 2nd set of textfields
panel.add(new JTextField(), "shrink, growx, top");
panel.add(new JTextField(), "grow, top");
panel.add(new JTextField(), "shrink, growx, top");
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
第二個和第五個文本字段按預期增長。其他人依照預期保持其規模,儘管他們的容器不「收縮」,並且正在處理與其他組件分開的空間。第二和第五個文本字段應該佔據所有「額外」空間。
+1好問題 – mKorbel