This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JEditorPane and JScrollPane

 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
when i add an html file to a editorpane and then add that to a jscrollpane, the scrollbar is completely at the bottom, while i want to have it at the top.
I looked at scrollbar methods, but can find the right method to do it.
Anyone have ideas ?
thanks
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
have you tried the scrollRectToVisible method?
This method takes a Rectangle as Argument. There you could create simply a new Rectangle(0,0,0,0).
I have never tried this, but it should work.
Good Luck

Rene
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks rene,

but this does not seem to work either. maybe i am doing something wrong.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try to call scrollRectToVisible after your dialog is visible. If this doesn't work, then maybe you should add an empty JEditorPane, then you show your dialog and then you add the content. The last two steps you can change if you don't like it that way. In a normal case scrollRectToVisible is not needed.
Hope that helps

Rene
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no does not work either.
anything i am doing wrong ?
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I wrote a little sample. At least for me it works fine. Can you test it please. It is very simple. If you press the button, then you can choose an HTML file, which will be displayed.
If this doesn't work for you at all, then maybe your JDK has a bug???
 
John Smith
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to try adding the line:

This should cause the scroll pane to be moved all the way up to the top.
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both ways work,
thanks very much
friso
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic