Solved

remove horizontal scrolling from jscrollpane

Posted on 2007-03-20
6
882 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
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

685 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