• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setSize()

 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic