Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JTextPane text wrap

Posted on 2000-04-28
4
Medium Priority
?
2,101 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 200 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

722 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