Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

remove horizontal scrolling from jscrollpane

Posted on 2007-03-20
6
Medium Priority
?
886 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
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!

 
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 1000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

688 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