繁体   English   中英

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

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

正如标题所说,我只是试图在TextArea上设置一个LineBorder设置的边距(提供一些填充)。 没有设置边框,.setMargins工作正常。 这是特定的代码块。

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);

我尝试过以下各项:

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

但是在应用边框后没有任何影响边距,填充总是为0.任何想法如何在带有边框的textArea上设置填充?

如果你尝试添加一个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