何かがおかしい。右端のボタン (以下の例では「ヘルプ」というラベルが付いています) を JFrame に右揃えにし、巨大なボタンの幅を JFrame に関連付けますが、それぞれ少なくとも 180px にしようとしています。巨大なボタンの制約が機能するようになりましたが、正しい配置ではありません。
gapbefore push
(この他のSOの質問のように)正しい配置が達成されたと思いましたが、わかりません。
誰でも私を助けることができますか?
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
public class RightAlignQuestion {
public static void main(String[] args) {
JFrame frame = new JFrame("right align question");
JPanel mainPanel = new JPanel();
frame.setContentPane(mainPanel);
mainPanel.setLayout(new MigLayout("insets 0", "[grow]", ""));
JPanel topPanel = new JPanel();
topPanel.setLayout(new MigLayout("", "[][][][]", ""));
for (int i = 0; i < 3; ++i)
topPanel.add(new JButton("button"+i), "");
topPanel.add(new JButton("help"), "gapbefore push, wrap");
topPanel.add(new JButton("big button"), "span 3, grow");
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new MigLayout("",
"[180:180:,grow][180:180:,grow]","100:"));
bottomPanel.add(new JButton("tweedledee"), "grow");
bottomPanel.add(new JButton("tweedledum"), "grow");
mainPanel.add(topPanel, "grow, wrap");
mainPanel.add(bottomPanel, "grow");
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}