JTextArea和JTextField在文本上的内部填充 [英] JTextArea and JTextField internal padding on text
问题描述
我想增加 JTextField 和
I would like to increase the spacing / padding / insets for the JTextField and JTextArea. Effectively increase the spacing between the two red lines in the image below:
推荐答案
您还可以尝试使用EmptyBorder在两个组件之间添加间隙.如果已经有边框,则可以将其与EmptyBorder结合使用以创建CompoundBorder.在下面的代码片段中,创建了一个新的CompoundBorder,它具有TitledBorder和EmptyBorder,后者在组件周围强制填充了1个像素.
You could also try using an EmptyBorder to put in gaps between the two components. If you already have a Border, you can use that in conjunction with an EmptyBorder to create a CompoundBorder. In the code fragment below, a new CompoundBorder is created that has a TitledBorder and an EmptyBorder which enforces a padding of 1 pixed around the component.
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)
)
);
这篇关于JTextArea和JTextField在文本上的内部填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!