Karlovsky120
Karlovsky120

Reputation: 6352

Merging JTextArea with JTextPane

My program originaly had JTextAreas, but when I needed to change spacing between rows of characters, I was forced to use JTextPanes. But JTextPane dont have any borders by default (unlike JTextAreas) and differ from JTextAreas in several visual ways.

I did ask a question about setting the JTextArea border to JTextPane already, however, I'm doing the whole package, a complete makeover. I am using Nimbus LAF, just to be clear.

My question is, how can I create a components that acts like a JTextPane, but looks like a JTextArea?

One way is to create a JTextArea and "retrain" it so it acts like a JTextPane (highly unlikely, I'm guessing), and other way is to create a JTextPane and "repaint" it so it looks just like a JTextArea.

I'm guessing I will be having fun with UIDefaults and what-not...

I am not sure if this is even possible, and if it is, I'd like to know which are the keys that need to be changed (the ones whose values are different inbetween JTextArea and JTextPane), or at least how can I determine them.

One very important thing is that I need to see the focus on my JTextComponent, it has to be painted and look like it's a regular JTextArea.

Is there a way I can achieve all this?

Upvotes: 0

Views: 178

Answers (1)

Ani
Ani

Reputation: 576

I didn't think they were different at all visually. Aren't they both just white boxes on a blue-ish background?

In any case, you can change the border using the jTextArea1.setBorder(Border b) method. There are about 8 options in the kind of border you can apply.

Upvotes: 1

Related Questions