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?
The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text.
Use textArea. append("text") , but I recomend JTextPane for more control like color, selection, etc.
It has built in support for HTML. No how. Look for another component.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With