Results 1 to 1 of 1
- 08-11-2007, 10:26 AM #1
Member
- Join Date
- Aug 2007
- Posts
- 1
- Rep Power
- 0
Internationalization: Select language from combo box
Hi, I'm trying to make the user select the language of a very simple menu.
I post here the 2 classes: Menus and Selector.
In the Menus class, there are 2 items: File and Help
When you click on File then you select Configuration, and it shows the Selector class which is only a ComboBox, where you select the Language.
The Menus class is in part internationalized because I defined a Resources file with this pairs:
TITLE=Internationalization!
FILE=File
HELP=Help
OPEN=Open
CONFIGURATION=Configuration
So that's first step is done, and it works fine, now I need the end user to select the language in the Configuration combo box and on the fly load TITLE, FILE,HELP,OPEN and CONFIGIRATION from an appropiate Resourses_es_ESP.properties file that I've already created, if for example he selects Spanish, that properties file has this pairs:
TITLE=Internationacionalizacion
FILE=Archivo
HELP= Ayuda
OPEN=Abrir
CONFIGURATION=Configuracion.
Any help please?
Here is the menu class just to select the Configuration option:
And here is the selector it's just a combo box to select the languageJava Code:import java.awt.event.*; import java.util.ResourceBundle; public class Menus extends javax.swing.JFrame { ResourceBundle res = ResourceBundle.getBundle("Resources"); public Menus() { setSize(500, 300); String title = res.getString("TITLE"); this.setTitle(title); initComponents(); } private void initComponents() { jmbarBarraDeMenus = new javax.swing.JMenuBar(); jmnuArchivo = new javax.swing.JMenu(); String fi = res.getString("FILE"); jmnuArchivo.setText(fi); jmbarBarraDeMenus.add(jmnuArchivo); jmbarBarraDeMenus.add(jmnuArchivo); jmnuHelp = new javax.swing.JMenu(); String hel = res.getString("HELP"); jmnuHelp.setText(hel); jmbarBarraDeMenus.add(jmnuHelp); jmnuAbrir = new javax.swing.JMenuItem(); String op = res.getString("OPEN"); jmnuAbrir.setText(op); jmnuArchivo.add(jmnuAbrir); jmnuConfigura = new javax.swing.JMenuItem(); String co = res.getString("CONFIGURATION"); jmnuConfigura.setText(co); jmnuArchivo.add(jmnuConfigura); jmnuConfigura.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuConf_actionPerformed(e); } }); getContentPane().setLayout(null); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); setJMenuBar(jmbarBarraDeMenus); }//GEN-END:initComponents /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { System.exit (0); } void jMenuConf_actionPerformed(ActionEvent e) { Selector dlg = new Selector(); dlg.setVisible(true) ; } public static void main (String args[]) { new Menus().setVisible(true); } private javax.swing.JMenuBar jmbarBarraDeMenus; private javax.swing.JMenu jmnuArchivo; private javax.swing.JMenu jmnuHelp; private javax.swing.JMenuItem jmnuAbrir; private javax.swing.JMenuItem jmnuConfigura; }
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Selector extends javax.swing.JFrame { /** Creates new form CAplicación */ private javax.swing.JLabel jEtSaludo; private javax.swing.JButton jBtSaludo; public Selector() // constructor { setSize(300, 200); // tamaño del formulario setTitle("Language Selector"); // título del formulario initComponents(); // iniciar controles o componentes } private void initComponents()//GEN-BEGIN:initComponents { getContentPane().setLayout(null); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); String[] langStrings = { "Spanish", "French", "Dutch", "Chinese", "English" }; JComboBox langList = new JComboBox(langStrings); langList.setSelectedIndex(4); getContentPane().add(langList); langList.setBounds(42,90,204,30); }//GEN-END:initComponents /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit (0); }//GEN-LAST:event_exitForm private void langListActionPerformed(java.awt.event.ActionEvent evt) { //do something } /** * @param args the command line arguments */ public static void main (String args[]) { new Selector().setVisible(true); } }
Similar Threads
-
Is it possible to get and store items to a variable in a combo box?
By Soda in forum New To JavaReplies: 2Last Post: 12-05-2007, 01:19 PM -
Combo Box Event handling
By smajidali26 in forum AWT / SwingReplies: 1Last Post: 11-29-2007, 05:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks