简体   繁体   中英

(Java) Change swing components' text at runtime (resource bundles)

I'm setting the value of a JLabel with

myLabel.setText( controller.getString("hello") );

where controller.getString returns the getString from a ResourceBundle instance.

However, I'm trying to update the language of the application at runtime and I'm having the hardest time to figure out how to 'refresh' the label's text so that it users the new Locale's getString.

I use an observer-pattern that updates my frame whenever the language is switched.

Any suggestions?

Thank you.

John Neumann.

If you call setText again, the label will be updated. So in your implementation of the Observer interface, when the language switches you can ensure all your labels are the right language by calling that same setText method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM