Forums Register Login

Panel sizing problem

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 993 times.
Similar Threads
Image not displayed in JEditorPane
Manually sizing JScrollPane
How to make JEditorPane scrollable?
How to add slider / knob to JScrollPane
Nested JPanels
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:26:57.