File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes add a JTextPane to a JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "add a JTextPane to a JScrollPane" Watch "add a JTextPane to a JScrollPane" New topic
Author

add a JTextPane to a JScrollPane

Michaela Fricker
Greenhorn

Joined: Oct 28, 2002
Posts: 16
Hi,
I use a JTextPane to display Text and JTable.
I added it to a JScrollPane, so that you can scroll if a line is longer than the viewport.
But only a vertical scrollbar appears and no horizontal.
Why does the scollPane act this way and what can i do to get my horizontal scrollbar?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Moving this to Swing...


Dave
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
Try looking at the JScrollPane API.
Notably methods and fields involving the horizontal and vertical scrollbar policies.
(Hint: use a different constructor)
Bill
Michaela Fricker
Greenhorn

Joined: Oct 28, 2002
Posts: 16
I've tried a different constructor.

I tried
HORIZONTAL_SCROLLBAR_ALWAYS and HORIZONTAL_SCROLLBAR_AS_NEEDED!
But it didn't help...
Is there any other chance?
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
You tried

and it didn't work? What JRE version and platform?
Bill
Michaela Fricker
Greenhorn

Joined: Oct 28, 2002
Posts: 16
Windows2000Professional and JRE 1.4.1 ...
Yes I tried it this way, and I've had a horizoltal ScrollBar visible, but it didn't do anything. At the End of the viewport the line didn't go on, it was written in an new line.
But with JEditorPane it worked so it should work in any way with JTextPane too.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
for what I know this behaviour of JTextPane is intended.
if you want to use JTextPane with a horizontal scrollbar you might have to extend it. Sorry, but I can't remember the exact solution. But there must be some documentation on this.
In any case, it is most certainly not the JScrollPane but the JTextPane that causes this behaviour.
Chantal
Michaela Fricker
Greenhorn

Joined: Oct 28, 2002
Posts: 16
I found a solution:
To force horizontal scrolling you have to override getScrollableTracksViewportWidth().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add a JTextPane to a JScrollPane