Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-11-2007, 12:26 PM
Member
 
Join Date: Aug 2007
Posts: 1
alejandrgarcia is on a distinguished road
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:


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; }
And here is the selector it's just a combo box to select the language


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); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SWT Combo JavaForums Java Blogs 0 12-31-2007 06:53 PM
Internationalization (2) JavaForums Java Blogs 0 12-23-2007 01:54 PM
Internationalization (I) JavaForums Java Blogs 0 12-23-2007 01:54 PM
Is it possible to get and store items to a variable in a combo box? Soda New To Java 2 12-05-2007 03:19 PM
Combo Box Event handling smajidali26 AWT / Swing 1 11-29-2007 07:57 PM


All times are GMT +3. The time now is 03:12 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org