Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add a JTextPane to a JScrollPane

 
Michaela Fricker
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to Swing...
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You tried

and it didn't work? What JRE version and platform?
Bill
 
Michaela Fricker
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a solution:
To force horizontal scrolling you have to override getScrollableTracksViewportWidth().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic