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.
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.
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.
Joined: Sep 24, 2003
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 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.
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
There are no new questions, but there may be new answers.
subject: JRadioButton labels don't change on repaint()