Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

line wrapping and scrolling in a JPanel

 
Mark Vermeersch
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I've got an empty JPanel to which I want to add an (unknown) number of JLabels. Each JLabel has a text which is just one word. When my program is adding JLabels to the JPanel, I want it to have the same behaviour as a normal text editor: when a line is full, the next line gets filled (line wrapping).

If I just keep adding JLabels to a JPanel of a fixed size with .add(), there's no line wrapping. I tried it by giving the JPanel a fixed size, flowLayout and nesting it within a JScrollPane, but it keeps filling one long line, instead of jumping to the next one.

Any obvious solutions??
Thanks
Mark
[ October 18, 2004: Message edited by: Mark Vermeersch ]
 
Matthew Taylor
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using the Component method .setSize() for the JPanel, try using the JComponent method .setPreferredSize(). Hope that helps.
 
Mike Rainville
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have looked at javax.swing.JTextArea?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's just one big word requiring wrapping, something like this maybe

 
Mark Vermeersch
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Rainville:
Have looked at javax.swing.JTextArea?


Sure, but I want this text behaviour for all the components inside the JPanel: labels, buttons,... everything should behave as a text that performs line wrapping.

But I think I can solve it by overwriting the getPreferredSize() method of the JPanel I'm using.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic