Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

adding JScrollbar/scroolpane to jtextpane?  RSS feed

 
son dunckley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a JTextpane where i will be adding instructions. I know this will not be large enough, but there is no further space on my interface, so I need to add either a scrollbar or scrollpane.

I have tried a few attempts at this but cannot get either to appear. Can anyone help me with this?

Should I be using a scrollbar or scrollpane for a textpanel?

I just need it so the user can scroll down the text which isn't visible.



I did read somewhere that the scrollbars will appear when the preferred size of the panel is greater than the size of the pane, but couldn't set this up.

Is it that I should use a JTextArea instead of a JTextPane?

Any pointers would be appreciated
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh you are so close it hurts! You have added your instructionTextPanel to the JTextPane - that it fine. Now when you add to the instructionPanel, you should add the slider not the instructionTextPanel.
Make this single change to your code:
 
son dunckley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stuart

Thanks very much for your reply. I adjusted that line but it then meant the instructionpanel didn't display at all. So I added it back and then added a new line to add the slider.

Still not showing though. Can you enlighten me a bit more?

new code is:



cheers
 
son dunckley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stuart

I finally got it to display. It was the setbounds for the scrollpane which needed altering and now once I add enough text to warrant a scrollbar it appears. Fantastic , thanks for your help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!