【发布时间】:2015-03-10 12:44:35
【问题描述】:
我正在使用 BoxLayout,并且有 2 个 JTextField。我需要为它们添加一些边距选项,因为它们离窗口边框太近了。
代码:
JPanel top = new JPanel();
top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS));
top.add(new JLabel("Recipient:"));
recipient.setMaximumSize( recipient.getPreferredSize() );
top.add(recipient);
top.add(new JLabel("Subject:"));
subject.setMaximumSize( subject.getPreferredSize() );
top.add(subject);
top.add(new JLabel("Message:"));
add("North", top);
如果我添加一个 HorizontalStrut,它只会影响标签,而不影响 TextFields。谢谢你的建议!
【问题讨论】:
标签: java swing margin textfield boxlayout