简体   繁体   中英

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. Without setting the Border, .setMargins works fine. 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?

What if you try adding a CompoundBorder , won't this do, this will give you almost same thing

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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