wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes JScrollPane without horizontal scrolling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane without horizontal scrolling" Watch "JScrollPane without horizontal scrolling" New topic
Author

JScrollPane without horizontal scrolling

Steve Wood
Ranch Hand

Joined: Jan 08, 2003
Posts: 137
Hi,
I am using a JScrollPane and want the contained JPanel (containing a JEditor pane and other components) to size horizontally with it. Basically, the scroll pane keeps allowing the text to carry on without wrapping the text (it provides horizontal scrolling instead).
So my problem is: I want a scroll pane which does not have horizontal scrolling and instead resizes the contained panel appropriately.
Any help is greatly appreciated. I'm having trouble getting the swing of it (pardon the I'm sure much used pun).
Cheers,
Steve
Joe Crew
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
Steve,
Here is what I did, hopefully it works for you too. I created a JtextPane. I then added the JTextPane TO a JPanel. I then added the JPanel TO a JScrollPane like the following:
JScrollPane jscroll = new JScrollPane(myPanel);
I had to do it in this manner to get the behavior I wanted. You may want to consider it and try it. After I added my JPanel to my JScrollPane, I used the following

You can also do the same for vertical scrollbars. There is also a third policy variable called
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
Hope this helps.
Joe Crew
Steve Wood
Ranch Hand

Joined: Jan 08, 2003
Posts: 137
Hi,
Thanks for the reply. I've tried out exactly what you've said and though the editor pane is initially at the correct size, if I expand the frame and then shrink the frame, the editor pane does not resize (the text is cut off and as expected there is no horizontal scrolling to view it).
I was wondering if I needed to get into events and resize the panel that way but it seemed a bit heavy going?!
Cheers,
Steve
Joe Crew
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
Steve,
When I wrote this for myself I did it as an applet, a text editor in an applet to be exact. Resizing the browser window resizes the applet for me just fine with the applet being contained in a table and the size of the table is a percentage size of the entire page itself. In my case, when I resize, it works just fine. So I can't really answer your past question about the events since I don't have that problem nor encountered it for myself. Sorry about that.
Joe Crew
Steve Wood
Ranch Hand

Joined: Jan 08, 2003
Posts: 137
Cheers anyway.
I'm working on a desktop application and everything has been really great so far except for this.
Thanks,
Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollPane without horizontal scrolling