• 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

JRadioButton labels don't change on repaint()

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I'm working on an app that allows the user to select between two languages: English and French. I've set up a JMenu labelled "Language" with two submenus: English and French. When the user selects either one, either of these code is run:



The loadEnglishMenus_Buttons() and loadFrenchMenus_Buttons() methods run just fine changing all the menus, buttons and labels to their appropriate language as provided by the corresponding PNSResource objects. However, for some reason I have two JRadioButtons on my interface whose labels won't change from what they were set to initially. The call to this.repaint() isn't affecting them for some reason. Anybody have any ideas as to why that might be? Please advise.

Alan
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you repaint a component, and it appears unchanged from the way it was before, that's because it IS unchanged from the way it was before. In other words, your code (which you didn't show us) doesn't change those components.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And really, if you're having to call repaint() at all, that means you're doing something wrong. If you change the state of a component from code in the Swing event thread then its visible form (what you see on the screen) will change. You don't have to call repaint(). So if you're finding you do have to call repaint() to get your component changes to appear, then you are doing the changes on some other thread. Which would be the wrong thing to do. The Swing threading tutorial explains how to do threading right in the Swing context.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

You were right about the call to repaint(). I didn't need it. I removed it and everything changes as expected except those JRadioButtons! The call to loadEnglishMenus_Buttons() and loadFrenchMenus_Buttons() does retrieve the necessary text from the PNSResource classes for all components, and when I step through Eclipse in debug mode the appropriate resource is being returned on the call messages.getString("rbtnSingleKeyword"). But the label in JRadioButton is unaffected from what it was initially.

Here's a snippet of the loadFrenchMenus_Buttons() method:



Alan
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I suspected... you aren't changing the radio buttons. Instead you're creating new ones. And since those new ones aren't the ones already displayed in the GUI, you don't see any changes in the GUI.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aaah. Now I get you. Get back to you in a bit.

Alan
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK...got it figured out. I had to create new methods that just changed the text and also influenced the size of the components without creating "new" components. Thanks for the guidance.

Alan
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alan Shiers wrote:OK...got it figured out. I had to create new methods that just changed the text and also influenced the size of the components without creating "new" components. Thanks for the guidance.

Alan


You would normally* revalidate() the container of the components in order to re-layout the GUI with the new sizes. While not always needed, it's good practice to repaint() after revalidating.

* unless you've fallen into the trap of using a null layout
reply
    Bookmark Topic Watch Topic
  • New Topic