2012-03-29 21 views
0

MiGレイアウトを使用して、このサンプルのようなレイアウトを実現したいと考えています。したがって、最後のJButtonはJFrameの下部にあります。Java Miglayoutギャッププッシュが希望通りに機能しない

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が数が可変であるということですので、私はミグレイアウトに行定義を使用することはできませんので、私は、このコード(およびいくつかの派生)

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"); 
} 
を試してみました

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

提案がありますか?前もって感謝します。

答えて

0

私はこれがあなたが望むように見えると思います。 (あなたの作業例えば名声)

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"); 
} 

私は、多くの状況(または「牝馬」、「fillx」)に有用であること)MigLayout(への最初のパラメータに「埋める」を見つけます。あなたのgaptopは0pxのギャップを与えていたと思います。

関連する問題