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

scrollpane  RSS feed

 
Randall Twede
Ranch Hand
Posts: 4585
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
horizontal scrollbar is not being displayed. vertical is.
if i make the frame narrower, the text wraps instead of the scrollbar being displayed.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Don't use magic numbers or literals. All classes will have variables defined for use with the methods of the class.

In the case of a BorderLayout you should be using BorderLayout.CENTER.



Don't hardcode the preferred size of a component. The preferred size should be dynamic so the scrollbars can adjust as text is added/removed.

To prevent wrapping check out No Wrap Text Pane.
 
Randall Twede
Ranch Hand
Posts: 4585
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't hardcode the preferred size of a component. The preferred size should be dynamic so the scrollbars can adjust as text is added/removed.

well, the eventual goal is to work sort of like Word or Open Office. if i change the page setup i want what is displayed on the screen to change. for example if i change paper size the words will wrap in a different place.

i also tried setSize(int, int) but that acts the same way.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to manipulate the preferred size to mimic a paper size then is should be done on the scroll pane, not the text pane.
 
Randall Twede
Ranch Hand
Posts: 4585
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i solved this particular problem, but it creates another.
what i did was set the preferred size of the JTextPane(i also gave it a compound border).
added it to a JPanel with a FlowLayout.
and put the JPanel in the JScrollPane.
it now looks and works almost exactly like other word processors except now it is limited to a single page.
but this is a different problem so i am marking this one resolved.
if you would like to see what it looks like now, here is the code:

i notice that Wordpad works differently than Open Office. it changes the width when you change the page setup, but it displays no border and it is one continuous piece of text. it does not display the separate pages. it does not even have a print preview. and this is the windows 8 version. duplicating this seems more promising.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!