2012-03-29 3 views
0

Я хочу получить макет, как в этом примере, используя макет МиГ. Таким образом, последний JButton расположен в нижней части JFrame.Java Miglayout gap push не работает по желанию

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

Моя проблема в том, что количество JButtons я хочу добавить переменную, поэтому я не могу использовать определение строки в МИГ макете, так что я попробовал этот код (и несколько выкладок)

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

Я нахожу «заполнить» в первых парах к MigLayout(), чтобы быть полезной во многих ситуациях (или «кобылках», «fillx»). Думаю, ваш ноутбук дал 0px-промежуток.