Solved

JTextPane text wrap

Posted on 2000-04-28
4
2,080 Views
Last Modified: 2010-08-05
I'm using a JTextPane inside a JScrollPane - a classical case:

JTextPane textPane = new JTextPane();

JScrollPane = new JScrollPane(textPane);

getContentPane().add(scrollPane);

So, this is how i add these two components on my JFrame.

When i type a lot of text into the JTextPane, a vertical scrollbar appears. However, if i have long lines in the JTextPane, a horizontal scrollbar doesn't appear. The lines get wrapped.

I want the horizontal scrollbar to appear.

I think there must be a line wrap option in the JTextPane attribute sets. However, i didn't succeed at finding them.

Or maybe i should do something with the JScrollPane?

I'd liked to get these few lines of code that solve the problem.

Thanks a lot.
0
Comment
Question by:Mindo
  • 3
4 Comments
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 50 total points
ID: 2760690
This appears to work for JTextPane:

    JTextPane text = new JTextPane() {
            public boolean getScrollableTracksViewportWidth() {
                return (getSize().width < getParent().getSize().width);
            }
            public void setSize(Dimension d) {
                if (d.width < getParent().getSize().width) {
                    d.width = getParent().getSize().width;
                }
                super.setSize(d);
            }
        };
    JScrollPane scroll = new JScrollPane(text);

Best regards,
Jim Cakalic


0
 
LVL 2

Author Comment

by:Mindo
ID: 2760761
Hmm, i added your code. The horizontal scrollbar doesn't appear though and the lines are still wrapped.
0
 
LVL 2

Author Comment

by:Mindo
ID: 2760763
Doesn't work.
0
 
LVL 2

Author Comment

by:Mindo
ID: 2760773
Sorry, i've messed up with my own code. Now i checked it once again. It works! Thanks, man.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

895 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

11 Experts available now in Live!

Get 1:1 Help Now