質問

MigLayoutする

それらのための質問のお馴染みの

質問に対してより適切な名前を考えることができませんでした申し訳ありません...

私は、次のように見えることになりますレイアウトを作成しようとしています:

+---------+---------+
|  btn1   |  btn2   |
+---------+---------+
|                   |
|       btn3        |
|                   |
+-------------------+

ウィンドウは、x軸とy軸で利用可能な空間のすべての両方を満たす必要がありbtn3 x軸(半分ずつ)、及び成分を記入すべきであるBTN1とBTN2コンポーネントをサイズ変更されたときに

どのようにこれを達成する?

ここで始めるためにいくつかのコードです

public static void main(String[] args)
{
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = window.getContentPane();

    cp.setLayout(new MigLayout(""));
    cp.add(new JButton("btn1"), "");
    cp.add(new JButton("btn2"), "");
    cp.add(new JButton("btn3"), "");

    window.pack();
    window.setVisible(true);
}
役に立ちましたか?

解決

このはMigLayoutでとても簡単です。

setLayout(new MigLayout("fill"));

add(new JButton("button 1"), "w 50%");
add(new JButton("button 2"), "w 50%, wrap");
add(new JButton("button 3"), "grow, push, span");
あなたはpstantonの元の質問を読んでいる場合、

、私は必要なレイアウト命令は、彼はそれを定式化する方法に非常に近いと思います。それは私がMigLayoutについて好きものだ:)

他のヒント

私はmiglayoutを使ったことがないが、それは次のようなものである必要があります:

...
cp.add(new JButton("btn1"));
cp.add(new JButton("btn2"), "wrap");
cp.add(new JButton("btn3"), "span");
...

ですから、このような何かをしたいです。

する

非常に / < "流れ方向" の下で、それを持っているのレイアウトデモスイングP>

ここでは、そのサンプルからのコードは次のとおりです。

JTabbedPane tabbedPane = new JTabbedPane();

tabbedPane.addTab("Layout: flowx, Cell: flowx", createFlowPanel("", "flowx"));
tabbedPane.addTab("Layout: flowx, Cell: flowy", createFlowPanel("", "flowy"));
tabbedPane.addTab("Layout: flowy, Cell: flowx", createFlowPanel("flowy", "flowx"));
tabbedPane.addTab("Layout: flowy, Cell: flowy", createFlowPanel("flowy", "flowy"));

public JPanel createFlowPanel(String gridFlow, String cellFlow) {
    MigLayout lm = new MigLayout("center, wrap 3," + gridFlow,
                                 "[110,fill]",
                                 "[110,fill]");

    JPanel panel = createTabPanel(lm);

    for (int i = 0; i < 9; i++) {
        JButton b = createButton("" + (i + 1));
        b.setFont(b.getFont().deriveFont(20f));
        panel.add(b, cellFlow);
    }

    JButton b = createButton("5:2");
    b.setFont(b.getFont().deriveFont(20f));
    panel.add(b, cellFlow + ",cell 1 1");

    return panel;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top