Results 1 to 1 of 1
Thread: JOptionPane dialog (Localizing)
-
JOptionPane dialog (Localizing)
Presented below is an interesting example that localize the JOptionPane.
Java Code:public class MessageBoxExample extends JPanel implements ActionListener { JButton go; AbstractButton button; ButtonGroup group; Locale locale; String msg ; public MessageBoxExample() { group = new ButtonGroup(); locale = Locale.US; // default value button = new JRadioButton("English", true); button.setActionCommand("en"); button.addActionListener(this); group.add(button); add(button); button = new JRadioButton("Francais"); button.setActionCommand("fr"); button.addActionListener(this); group.add(button); add(button); go = new JButton("Do it"); go.addActionListener(this); add(go); locale = Locale.US; } public void setUILanguage() { ResourceBundle rb; rb = ResourceBundle.getBundle("JOptionPane", locale); UIManager.put("OptionPane.yesButtonText", rb.getString("Yes")); UIManager.put("OptionPane.noButtonText", rb.getString("No")); UIManager.put("OptionPane.cancelButtonText", rb.getString("Cancel")); msg = rb.getString("SaveMsg"); } public void actionPerformed(ActionEvent e) { int result; if (e.getSource() instanceof JRadioButton) { if (e.getActionCommand().equals("en")) locale = Locale.US; else locale = Locale.FRANCE; setUILanguage(); } else { // the button action result = JOptionPane.showConfirmDialog(this,msg); System.out.println(result); } } public Dimension getPreferredSize(){ return new Dimension(200, 200); } public static void main(String s[]) { JFrame frame = new JFrame(""); MessageBoxExample panel = new MessageBoxExample(); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); frame.getContentPane().add(panel,"Center"); frame.setSize(panel.getPreferredSize()); frame.setVisible(true); } }
Similar Threads
-
JOptionPane (customizing)
By Java Tip in forum Java TipReplies: 0Last Post: 03-14-2008, 11:39 AM -
JOptionPane - message dialog
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:11 AM -
JOptionPane - input dialog
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:09 AM -
About JOptionPane.showMessageDialog
By jhetfield18 in forum AWT / SwingReplies: 2Last Post: 11-02-2007, 10:45 PM -
problems with JOptionPane
By oregon in forum AWT / SwingReplies: 2Last Post: 08-05-2007, 05:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks