1
我想对齐2个JPanles在一个大的面板。我无法正确对齐它们。我将链接指向源代码here。如果您运行源代码,您可以看到新付款方式单选按钮位于中心位置,而不仅仅位于付款选项面板下方。我如何得到它。我非常抱歉无法发布屏幕截图以及长代码。提前致谢。JPanel的不对齐正确
我想对齐2个JPanles在一个大的面板。我无法正确对齐它们。我将链接指向源代码here。如果您运行源代码,您可以看到新付款方式单选按钮位于中心位置,而不仅仅位于付款选项面板下方。我如何得到它。我非常抱歉无法发布屏幕截图以及长代码。提前致谢。JPanel的不对齐正确
作为替代,请考虑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();
}
});
}
}
只有一个选择的OP,尝试 - 错误 - 读取API - ...永远,因为我们都在这里/围绕+1 – mKorbel
考虑发布的[SSCCE(http://sscce.org)如果你最终在这里没有得到任何帮助。 – aioobe
和为什么新的线程,而不是继续http://stackoverflow.com/questions/6908535/not-able-to-add-3-jpanels-to-a-main-panel – mKorbel