我想增加JTextField和JTextArea的间距/填充/插入。有效增加了两条红线之间的间距如下图所示:文本上的JTextArea和JTextField内部填充
alt text http://i49.tinypic.com/2jb2idf.jpg
我想增加JTextField和JTextArea的间距/填充/插入。有效增加了两条红线之间的间距如下图所示:文本上的JTextArea和JTextField内部填充
alt text http://i49.tinypic.com/2jb2idf.jpg
您也可以尝试使用EmptyBorder放置两个组件之间的间隙。如果您已经有了边框,可以将它与EmptyBorder一起使用来创建一个CompoundBorder。在下面的代码片段中,创建了一个新的CompoundBorder,它有一个TitledBorder和一个EmptyBorder,它强制在组件周围填充1像素。
testPanel.setBorder(
javax.swing.BorderFactory.createCompoundBorder(
javax.swing.BorderFactory.createTitledBorder(
null, "Border Title",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font("Verdana", 1, 11)
),
javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)
)
);
您是否尝试过的方法setMargin?
实现这一目标的最简单方法是:
yourVariableName.setMargin(new Insets(2,2,2,2));
的数字代表(上,左,下,右)。适用于JTextField和JTextArea