Adding margins in a JTextArea?

user2027425 picture user2027425 · Feb 7, 2013 · Viewed 9.8k times · Source

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?

Answer

Smit picture Smit · Feb 7, 2013

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