Link to home
Start Free TrialLog in
Avatar of Vel Eous
Vel Eous

asked on

remove horizontal scrolling from jscrollpane

How would I amend the following code so that it had no horizontal scrolling ?

getContentPane().add(new JScrollPane(jtextAreaDisplay), BorderLayout.CENTER);
Avatar of mr_egyptian
mr_egyptian
Flag of United States of America image

try the following:

yourScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

The options are:
    *  JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
    * JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
    * JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
and the same is available for the vertical scroll bar.
Avatar of Vel Eous
Vel Eous

ASKER

I dont appear able to do that due to the way I have set up my scrollpane:



JTextArea jtextAreaDisplay = new JTextArea();

getContentPane().add(new JScrollPane(jtextAreaDisplay), BorderLayout.CENTER);
You can also set these in the constructor, like so:

JScrollPane(Component view, int vsbPolicy, int hsbPolicy)

So for you it would be:

getContentPane().add(new JScrollPane(jtextAreaDisplay, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);


I don't know what is thought to be best practice, but I alway create a named instance for any component I use.  When I don't, I always seem to run into trouble later.
Oops. That should be:

getContentPane().add(new JScrollPane(jtextAreaDisplay, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
Hmmm, ok that compiles, but my text still disapears off the screen ...   :/
ASKER CERTIFIED SOLUTION
Avatar of mr_egyptian
mr_egyptian
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial