大きなパネルに 2 つの JPanles を並べようとしています。それらを適切に整列させることができません。ここにソース コードへのリンクを示します。ソース コードを実行すると、[新しい支払い方法] ラジオ ボタンが支払いオプション パネルのすぐ下ではなく、中央にあることがわかります。どうすればそこにたどり着けますか。スクリーンショットを投稿できなかったことと、長いコードについて非常に申し訳ありません。事前にトンを感謝します。
1 に答える
2
別の方法として、以下に示すを検討BoxLayout
してください。
import java.awt.EventQueue;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
/** @see http://stackoverflow.com/questions/6911309 */
public class PaymentPanel extends Box {
public PaymentPanel() {
super(BoxLayout.Y_AXIS);
this.add(new JLabel("Payment Setup"));
this.add(Box.createVerticalStrut(10));
this.add(new JRadioButton("New payment Method", true));
this.add(Box.createVerticalStrut(10));
this.add(new JLabel("Invoice"));
}
private void display() {
JFrame f = new JFrame("PaymentPanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new PaymentPanel().display();
}
});
}
}
于 2011-08-02T13:38:19.730 に答える