Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding margins in a JTextArea?

So I have a JTextArea which shows the text right from the top left corner. I want some margin on all 4 sides, so there's some space between text and boundary of the area.

I have researched a lot and could not find any solution. How can I do it?

Also, I was thinking maybe put up a label on all 4 sides to create dummy margin. How can I create a JLabel with certain width and height?

like image 324
user2027425 Avatar asked Feb 06 '13 23:02

user2027425


People also ask

Is JTextArea editable?

The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text.

How do I add text to JTextArea?

Use textArea. append("text") , but I recomend JTextPane for more control like color, selection, etc.

Does JTextArea support HTML?

It has built in support for HTML. No how. Look for another component.


1 Answers

May be I dont understand your question correctly. However you can use setMargin()

// set the margin for all four sides
tt.setMargin( new Insets(10,10,10,10) ); // tt is JTextArea instance

Some Important Links

1. setMargin API

2. Class Insets

like image 87
Smit Avatar answered Nov 08 '22 12:11

Smit