• Post Reply Bookmark Topic Watch Topic
  • New Topic

setSize()  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it that whenever I use this method on a component (JPanel, JScrollPane, JList etc.), it makes not one iota of a difference to its actual size?
Paul
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setPreferredSize. When doing layout, prefer methods defined in swing components (e.g. javax.swing.JComponent) over those in awt components (e.g. java.awt.Component).
Now, don't expect all layout managers to respect the preferred size of a component. You may want to use setMinimumSize and/or setMaximumSize, if that is really what you want to do. Don't use those just to set the initial size.
Bill
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill. I'm kinda going back to my original question about JList. I want to display a box that contains nothing but could contain a rapidly increasing list of strings.
I want the box to look something like the thing I'm typing into now but I have no idea how to get the thing to display unless I add a vector containing information - and I still have no control over the size of it.
How do I display a box, which never changes its size whether there's data in it or not?
Paul
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you adding data to the JList?
I think the problem may be more with your layout manager than your component or data. What layout manager are you using?
For example, if you used BorderLayout and added the JList, in a JScrollPane, to your panel at BorderLayout.CENTER, it should stretch in both directions.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!