简体   繁体   English

Java Swing - 使用Line Border在TextArea上设置边距

[英]Java Swing - setting margins on TextArea with Line Border

As the title says, I am simply trying to set the margins (provide some padding) on a TextArea with a LineBorder set. 正如标题所说,我只是试图在TextArea上设置一个LineBorder设置的边距(提供一些填充)。 Without setting the Border, .setMargins works fine. 没有设置边框,.setMargins工作正常。 Here is the specific chunk of code. 这是特定的代码块。

aboutArea = new JTextArea("program info etc.....");

Border border = BorderFactory.createLineBorder(Color.BLACK);

aboutArea.setSize(400, 200);
aboutArea.setBorder(border);
aboutArea.setEditable(false);
aboutArea.setFont(new Font("Verdana", Font.BOLD, 12));

add(aboutArea);

I have tried each of these: 我尝试过以下各项:

aboutArea.setMargins(10,10,10,10);
.getBorders(aboutArea).set(10,10,10,10);
UIManager.put("aboutArea.margin", new Insets(10, 10, 10, 10));

but nothing affects the margins after I apply the border, the padding is always 0. Any ideas how to set the padding on the textArea with the border? 但是在应用边框后没有任何影响边距,填充总是为0.任何想法如何在带有边框的textArea上设置填充?

What if you try adding a CompoundBorder , won't this do, this will give you almost same thing 如果你尝试添加一个CompoundBorder会怎么样,这不会给你带来几乎相同的东西

JTextArea tarea = new JTextArea("program info etc.");
Border border = BorderFactory.createLineBorder(Color.BLACK);
tarea.setBorder(BorderFactory.createCompoundBorder(border, 
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));

检查中间JTextArea为OUTPUT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM