Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Disabling Choice Auto-expansion  RSS feed

 
Richard Teston
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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!!!
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!