Solved

JTextPane text wrap

Posted on 2000-04-28
4
2,077 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
Comment Utility
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
Comment Utility
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
Comment Utility
Doesn't work.
0
 
LVL 2

Author Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

772 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

12 Experts available now in Live!

Get 1:1 Help Now