我正在编写一个可通过单击按钮更改GUI语言的程序。我正在使用ResourceBundle来获取键值对。但是当我更改语言环境GUI语言时,不会改变...
有什么方法可以执行而无需重新启动程序?
public class Language extends JPanel{
public JButton Back = new JButton("Done");
public static JComboBox<Locale> LangCBox;
private static ResourceBundle message = ResourceBundle.getBundle("messagesBundle",Language.getDefaultLocale());
private Locale locale;
public Language()
{
langPanel = new JPanel();
langPanel.setLayout(null);
this.setLayout(new BorderLayout());
Back.setBounds(200, 250, 100, 20);
Back.addActionListener(listen);
langPanel.add(Back,"Center");
LangCBox = new JComboBox();
LangCBox.addItem(new Locale("ko","KR"));
LangCBox.addItem(new Locale("en","US"));
LangCBox.addItem(new Locale("zh","CN"));
LangCBox.addItemListener(itemEvent -> SetLanguage());
langPanel.add(LangCBox);
LangCBox.setBounds(150, 150, 200, 20);
this.add(langPanel);
}
ActionListener listen = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==Back)
{
Application.MyCard.card.show(Application.mainPanel,"LogIn");
}
}
};
public void SetLanguage()
{
ResourceBundle.clearCache();
Locale locale = LangCBox.getItemAt(LangCBox.getSelectedIndex());
message = ResourceBundle.getBundle("Messagesbundle",locale);
validate();
}
public static String getString(String key)
{
return message.getString(key);
}
}