• 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

Disabling Choice Auto-expansion

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have this frame with a choice in it. it has an item that is a string with a length of 50 characters. When i lost focus to that panel and get back to it, the choice is expanding its length according to item's length. So when i have long string in it, it expand and shrinking other components besides it. How do i fix the length of choice even when i lost focus on it and get back to it, the length is rock steady (beside of course when i stretch the frame). Please HELP ME!!!
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you tried calling setSize() on it?
Also, try adding it with a layout manager that won't resize it, like Flow layout, or Box layout, etc.
 
Richard Teston
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...yeah i've tried the Flowlayout but the choice component behavior still the same, it expands according the to length of item added into it.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've found 3 solutions to your problem...
  • Add the Choice to a container with a null layout and call setBounds() on the Choice with the size you want it to be. Drawback - you'll have to call setBounds() on every other component in that Container, and you'll have to code your own listeners for resizing.
  • Extend Choice and have it's getPreferredSize() method return the size you want your Choice component to be. You could even add a setPreferedSize() method that would let you modify the value it returns. Drawback - no major one's I can think of...
  • Redo your GUI in Swing, use a JComboBox instead of a Choice, and call setPreferredSize() on the JComboBox, passing in the size you want it to be. Drawback - You'll have to redo your GUI in Swing...


  • Choose yer poison...

    -nate
    reply
      Bookmark Topic Watch Topic
    • New Topic