Solved

JTextPane text wrap

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

623 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