Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JScrollPane without horizontal scrolling

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers anyway.
I'm working on a desktop application and everything has been really great so far except for this.
Thanks,
Steve
 
    Bookmark Topic Watch Topic
  • New Topic