• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Panel sizing problem

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Maybe he went home and went to bed. And took this tiny ad with him:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic