我使用的是BoxLayout,我有2 JTextFields。我需要为它们添加一些空白选项,因为它们离窗口边框太近。

代码:
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不影响。谢谢你的忠告!
发布于 2015-01-12 17:13:07
向面板中添加一个Border:
JPanel top = new JPanel();
top.setBorder( BorderFactory.createEmptyBorder(....) );有关更多信息和示例,请参阅有关如何使用边界的Swing教程中的部分。
https://stackoverflow.com/questions/27907268
复制相似问题