Solved

JTextPane text wrap

Posted on 2000-04-28
4
2,093 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
[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
  • 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven module vs maven project 3 116
String array comparison 4 57
Tagging and Merging on Branch 1 68
jmeter usage 4 63
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 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