Solved

remove horizontal scrolling from jscrollpane

Posted on 2007-03-20
6
876 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:Tchuki
  • 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:Tchuki
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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:Tchuki
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now