Solved

remove horizontal scrolling from jscrollpane

Posted on 2007-03-20
6
884 Views
Last Modified: 2012-08-13
How would I amend the following code so that it had no horizontal scrolling ?

getContentPane().add(new JScrollPane(jtextAreaDisplay), BorderLayout.CENTER);
0
Comment
Question by:Vel Eous
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:mr_egyptian
ID: 18761062
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.
0
 
LVL 14

Author Comment

by:Vel Eous
ID: 18761104
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);
0
 
LVL 15

Expert Comment

by:mr_egyptian
ID: 18761390
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:mr_egyptian
ID: 18761401
Oops. That should be:

getContentPane().add(new JScrollPane(jtextAreaDisplay, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
0
 
LVL 14

Author Comment

by:Vel Eous
ID: 18762748
Hmmm, ok that compiles, but my text still disapears off the screen ...   :/
0
 
LVL 15

Accepted Solution

by:
mr_egyptian earned 250 total points
ID: 18764339
Ok.  So you want to wrap text?  JScrollPane probably isn't the best choice.  Are you filling this with just text?

Why not just use a simple JTextArea?  If you need more features, such as graphics, etc look at JTextPane, or JEditorPane.

Here is the Sun tutorial page where you can get some sample code:
http://java.sun.com/docs/books/tutorial/uiswing/components/text.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question