0

MiGレイアウトを使用して、このサンプルのようなレイアウトを実現したいと思います。したがって、最後のJButtonはJFrameの下部にあります。

public class MainFrame extends JFrame {

    public static void main(String[] args) {
         MainFrame mainFrame = new MainFrame();
         mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
         mainFrame.setPreferredSize(new Dimension(400, 300));
         mainFrame.pack();
         mainFrame.setLocationRelativeTo(null);
         mainFrame.setVisible(true);
    }

    public MainFrame() {
        this.setLayout(new MigLayout("debug", "[grow, fill]", "[][][]push[]"));
        this.add(new JButton("Test1"), "wrap");
        this.add(new JButton("Test2"), "wrap");
        this.add(new JButton("Test..."), "wrap");
        this.add(new JButton("TestBottom"), "");
    }
}

私の問題は、追加したいJButtonの数が可変であるため、MiGレイアウトで行定義を使用できないことです。そこで、このコード(およびいくつかの派生)を試しました。

public MainFrame() {
    this.setLayout(new MigLayout("debug", "[grow, fill]", ""));
    this.add(new JButton("Test1"), "wrap");
    this.add(new JButton("Test2"), "wrap");
    this.add(new JButton("Test..."), "wrap");
    this.add(new JButton("TestBottom"), "gaptop push");
}

しかし、残念ながら、これは期待どおりに機能しません。

助言がありますか?前もって感謝します。

4

1 に答える 1

0

これはあなたが望むもののように見えると思います。(あなたの実例のためのkudos)

public MainFrame() {
    this.setLayout(new MigLayout("debug, filly", "[grow, fill]", ""));
    this.add(new JButton("Test1"), "wrap");
    this.add(new JButton("Test2"), "wrap");
    this.add(new JButton("Test..."), "wrap");
    this.add(new JButton("TestBottom"), "push, bottom");
}

MigLayout()の最初のパラメーターの「fill」は多くの状況(または「filly」、「fillx」)で役立つことがわかりました。あなたのギャップトップは私が思うに0pxのギャップを与えていました。

于 2012-03-29T16:03:49.720 に答える