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

viewports and scrollbars  RSS feed

Joe Crew
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I've created a JTextPane to be a text editor. I added the JTextPane to a JScrollPane so I can scroll the JTextPane when needed. Now I need to enforce some of the limits of the size of the area. The user enters in the height and width of the JTextPane when the start the app:> java texteditor 3.0 4.0
When the user enters in the height and width, and the sizes are smaller than the screen size, I set the scrollpane properties scroll.VERTICAL_SCROLLBAR_NEVER and scroll.HORIZONTAL_SCROLLBAR_NEVER. This of course says there are no scrollbars and works fine. BUT the problem is when the user gets to the bottom of the JTextPane and keeps typing in text, they are allowed to do it. I don't want the user to be able to do this. If the user defines an area as 3" by 4", that is ALL I want them to have and nothing more. I called getScrollableTracksViewportHeight() and it indicates false when I think I need it to be true. But I see no property to setScrollableTracksViewportHeight(). Is there any way to stop the user from being able to type in text when they reach the bottom of a JTextPane?
Also sometimes the user will enter they want their editor to be 10 inches wide and 8 inches in height. Since this is a larger area than the 640x480 screen they are using, my editor automatically put in scrollbars so they can get their full 10x8 required size. Now the horizontal and vertical scrollbars are turned on, no problem. However, when the user reaches their limit of 10 inches wide, I want to force word wrap. It's like I want to define the viewport to have viewable width of say 5 inches, but I want to the total width to be 10 inches only. I want to turn on the scrollbars, but then stop the user at 10 inches. Is there a way to make the entire JTextPane 10 inches wide, but make the viewable part of it 5 inches wide. I hope you all can understand what I am asking here. Please let me know if you need more clarification. Any ideas would be appreciated.
Thanks in advance,
Joe Crew
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!