私は最初にこの質問を milayout フォーラムに投稿しましたが、534 回の閲覧と回答がなかったので、そこで試してみることにしました ;-)
ダイアログの下部に常に残る「OK」ボタンを追加するために、MigLayout ホワイトペーパーの「最初の例」を拡張しようとしました。
残念ながら、私が見つけた唯一の解決策は、成長する「偽のパネル」を追加することでした。
public class TestResize extends JDialog {
protected JPanel contentPane;
public TestResize() {
super((Dialog) null, "Test resize", true);
setupUI();
setContentPane(contentPane);
}
private void setupUI() {
contentPane = new JPanel(new MigLayout());
contentPane.add(new JLabel("Enter size:"), "");
contentPane.add(new JTextField(""), "grow, pushx, wrap");
contentPane.add(new JLabel("Enter weight:"), "");
contentPane.add(new JTextField(""), "grow, pushx, wrap");
// fake panel that is allowed to grow
contentPane.add(new JPanel(), "span 2, grow, pushy, wrap");
JButton okButton = new JButton("Ok");
JPanel buttonPanel = new JPanel(new MigLayout("", "[center, grow]"));
buttonPanel.add(okButton, "");
contentPane.add(buttonPanel, "dock south");
}
public static void main(String[] args) {
TestResize dialog = new TestResize();
dialog.pack();
dialog.setVisible(true);
}
}
私は本当にこのアプローチがまったく好きではありません...しかし、より良い方法はありますか?
(写真のアップロードは許可されていないようですが、取得したいUIは元の投稿に表示されています)
ありがとう!