Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Panel sizing problem  RSS feed

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JScrollPane that contains a JPanel that contains a JEditorPane. So it's a bit like this:

|--------------------
|JScrollPane
| |------------------
| |JPanel
| | |----------------
| | |JEditorPane
| | |

The reason for this is because the JPanel also contains some other controls.

The difficulty I'm having is that the JEditorPane isn't wrapping the text as it is unconstrained by width (because of the scrollpane). So as a result, each paragraph in the HTML is shown as a single, very long, very wide line.

Is there any way to tell Swing to contrict the width of the JPanel to the size of the JScrollPane viewport?

Any ideas how to get around this problem? If I drop the editorpane into a scrollpane, everything works fine.

Any help is much appreciated.

Cheers,

Steve
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've not tried this, but in looking over the API documentation I see some methods that might help. My thoughts:

Get the JScrollPane's JViewport with JScrollPane.getViewPort().

Get the size of the viewport by calling JViewport.getViewSize().

Set the size of the JPanel to this with setSize() or setPreferredSize().

My question for you is: wouldn't shrinking the JPanel (which is contained by the JScrollPane) to the size of the JScrollPane's viewport eliminate the need for a JScrollPane?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!