Hi all,
I have a property file to which i have a resource
bundle instance associated. Now whenever the property file is changed, i want
the resource bundle instanced to be refreshed with the new values. Is there any
way/pattern/listner through which i can do this
thanx and regards
KR Kumar
===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
From owner-j2ee-interest@JAVA.SUN.COM Tue, 5 Dec 2006 07:59:18
Return-Path:
Delivery-Date: Fri, 08 Dec 2006 22:13:16 -0500
Received-SPF: none (mxus8: 192.18.99.108 is neither permitted nor denied by domain of JAVA.SUN.COM) client-ip2.18.99.108; envelope-from=owner-j2ee-interest@JAVA.SUN.COM; helo=swjscmail2.java.sun.com;
Received: from [192.18.99.108] (helo=swjscmail2.java.sun.com)
by mx.perfora.net (node=mxus8) with ESMTP (Nemesis),
id 0MKqB5-1GsseJ3L3J-0003Lk for java@JUNLU.COM; Fri, 08 Dec 2006 22:13:16 -0500
Received: from swjscmail1 (swjscmail1.Sun.COM [192.18.99.107])
by swjscmail2.java.sun.com (Postfix) with ESMTP
id 69ED221D29; Fri, 8 Dec 2006 20:10:47 -0700 (MST)
Received: from JAVA.SUN.COM by JAVA.SUN.COM (LISTSERV-TCP/IP release 1.8e) with
spool id 4971613 for J2EE-INTEREST@JAVA.SUN.COM; Fri, 8 Dec 2006
20:08:29 -0700
X-Original-To: j2ee-interest@java.sun.com
Delivered-To: j2ee-interest@java.sun.com
Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.228])
by swjscmail1.java.sun.com (Postfix) with ESMTP id 0C5EE360BA for
; Tue, 5 Dec 2006 06:03:15 -0700 (MST)
Received: by wx-out-0506.google.com with SMTP id h30so4199911wxd for
; Tue, 05 Dec 2006 05:07:48 -0800 (PST)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s¾ta; d=gmail.com;
h=received:message-id:from:to:subject:date:mime-version:content-type:content-transfer-encoding:x-priority:x-msmail-priority:x-mailer:x-mimeole;
b=aP/IkuclWXKK7UBImWAiNmxciyW++ELlFvwciFwURPKEz+GM6TBsjMHzbFK4yUnv8hcxKeezmsazAP375BIAYfLMKow7WpPEgaB0XPMtueg1Q2Bdk3QziKW7CaNy0LneHMZq1DWkl918VsGBygp+uJ+mbFMGPbxDPBXVhLE5w3AReceived: by 10.70.59.17 with SMTP id h17mr17412929wxa.1165324067981; Tue, 05
Dec 2006 05:07:47 -0800 (PST)
Received: from bloodlust ( [69.60.116.247]) by mx.google.com with ESMTP id
i11sm38056546wxd.2006.12.05.05.07.36; Tue, 05 Dec 2006 05:07:47 -0800
(PST)
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
Content-Transfer-Encoding: 8bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Message-ID: <000201c7186e$4590b890$13d3dcc9@bloodlust>
Date: Tue, 5 Dec 2006 07:59:18 -0500
Reply-To: "A mailing list for Java(tm) 2 Platform, Enterprise Edition"
Sender: "A mailing list for Java(tm) 2 Platform, Enterprise Edition"
From: Ne'Bahn
Subject: UI troubles...
To: J2EE-INTEREST@JAVA.SUN.COM
Precedence: list
Envelope-To: java@JUNLU.COM
Hi list, I'm wondering if there is a way to "justify" components on a JFrame
/ JDialog or wherever they are...The problem is: I've a UI and I want to
show it in many languages (I18n), but when language change take place the UI
comes "crazy", for example: text on buttons doesn't fit, text labels are
truncated and so on. Any one has dealing with this prior ???
Thanks in advance...
--------------------
filename: I18n.java
--------------------
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class I18n extends JFrame {
private JPanel shoppingCartPanel = new JPanel();
private JPanel customerPanel = new JPanel();
private JLabel applesLabel = new JLabel();
private JLabel peachesLabel = new JLabel();
private JLabel pearsLabel = new JLabel();
private JLabel totalItemsLabel = new JLabel();
private JLabel itemsLabel = new JLabel();
private JLabel totalCostLabel = new JLabel();
private JLabel costLabel = new JLabel();
private JLabel customerIDLabel = new JLabel();
private JLabel creditCardLabel = new JLabel();
private JTextField applesTextField = new JTextField();
private JTextField peachesTextField = new JTextField();
private JTextField pearsTextField = new JTextField();
private JTextField customerIDTextField = new JTextField();
private JTextField creditCardTextField = new JTextField();
private JButton purchaseButton = new JButton();
private JButton clearButton = new JButton();
private Locale locale = null;
private ResourceBundle resourceBundle = null;
private NumberFormat numberFormat = null;
public I18n(String language, String country) {
locale = new Locale(language, country);
resourceBundle = ResourceBundle.getBundle("Text", locale);
numberFormat = NumberFormat.getNumberInstance(locale);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setTitle(resourceBundle.getString("title"));
this.getContentPane().setLayout(null);
this.setSize(new Dimension(316, 309));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getRootPane().setDefaultButton(purchaseButton);
// SHOPPING CART panel
shoppingCartPanel.setBounds(new Rectangle(10, 5, 290, 145));
shoppingCartPanel.setLayout(null);
shoppingCartPanel.setBorder(BorderFactory.createTitledBorder(resourceBundle.getString("shopping_cart")));
shoppingCartPanel.add(peachesTextField, null);
shoppingCartPanel.add(applesTextField, null);
shoppingCartPanel.add(costLabel, null);
shoppingCartPanel.add(totalCostLabel, null);
shoppingCartPanel.add(itemsLabel, null);
shoppingCartPanel.add(totalItemsLabel, null);
shoppingCartPanel.add(pearsLabel, null);
shoppingCartPanel.add(peachesLabel, null);
shoppingCartPanel.add(applesLabel, null);
shoppingCartPanel.add(pearsTextField, null);
applesLabel.setText(resourceBundle.getString("apples"));
applesLabel.setBounds(new Rectangle(25, 23, 40, 15));
applesLabel.setDisplayedMnemonic('A');
peachesLabel.setText(resourceBundle.getString("peaches"));
peachesLabel.setBounds(new Rectangle(25, 47, 50, 15));
peachesLabel.setDisplayedMnemonic('E');
pearsLabel.setText(resourceBundle.getString("pears"));
pearsLabel.setBounds(new Rectangle(25, 73, 40, 15));
pearsLabel.setDisplayedMnemonic('A');
totalItemsLabel.setText(resourceBundle.getString("total_tems"));
totalItemsLabel.setBounds(new Rectangle(25, 100, 75, 15));
totalItemsLabel.setFont(new Font("Tahoma", 1, 11));
itemsLabel.setText("0");
itemsLabel.setBounds(new Rectangle(100, 100, 175, 15));
totalCostLabel.setText(resourceBundle.getString("total_cost"));
totalCostLabel.setBounds(new Rectangle(25, 120, 65, 15));
totalCostLabel.setFont(new Font("Tahoma", 1, 11));
costLabel.setText("0");
costLabel.setBounds(new Rectangle(100, 120, 175, 15));
applesTextField.setBounds(new Rectangle(75, 20, 200, 20));
peachesTextField.setBounds(new Rectangle(75, 45, 200, 20));
pearsTextField.setBounds(new Rectangle(75, 70, 200, 20));
// CUSTOMER panel
customerPanel.setBounds(new Rectangle(10, 150, 290, 80));
customerPanel.setLayout(null);
customerPanel.setBorder(BorderFactory.createTitledBorder(resourceBundle.getString("customer")));
customerPanel.add(creditCardTextField, null);
customerPanel.add(customerIDTextField, null);
customerPanel.add(creditCardLabel, null);
customerPanel.add(customerIDLabel, null);
customerIDLabel.setText(resourceBundle.getString("customer_ID"));
customerIDLabel.setBounds(new Rectangle(25, 22, 70, 15));
customerIDLabel.setDisplayedMnemonic('U');
creditCardLabel.setText(resourceBundle.getString("credit_card"));
creditCardLabel.setBounds(new Rectangle(25, 47, 60, 15));
creditCardLabel.setDisplayedMnemonic('D');
customerIDTextField.setBounds(new Rectangle(95, 20, 180, 19));
creditCardTextField.setBounds(new Rectangle(95, 45, 180, 19));
// UI
purchaseButton.setText(resourceBundle.getString("purchase"));
purchaseButton.setBounds(new Rectangle(130, 240, 80, 25));
purchaseButton.setMnemonic('P');
purchaseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
purchaseButton_actionPerformed(e);
}
});
clearButton.setText(resourceBundle.getString("clear"));
clearButton.setBounds(new Rectangle(220, 240, 80, 25));
clearButton.setMnemonic('C');
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clearButton_actionPerformed(e);
}
});
this.getContentPane().add(clearButton, null);
this.getContentPane().add(purchaseButton, null);
this.getContentPane().add(customerPanel, null);
this.getContentPane().add(shoppingCartPanel, null);
}
private void purchaseButton_actionPerformed(ActionEvent e) {
if (e != null) {
}
}
private void clearButton_actionPerformed(ActionEvent e) {
if (e != null) {
}
}
public static void main(String[] args) {
I18n i18n = new I18n("de", "DE");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = i18n.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
i18n.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
i18n.setVisible(true);
}
}
----------------------------------
filename: Text_de_DE.properties
----------------------------------
# Application title
title = Fr?chte 1.25 jede
# Labels
apples = ?pfel:
peaches = Birnen:
pears = Pfirsiche:
total_tems = Anzahl Fr?chte:
total_cost = Gesamtkosten:
credit_card = Kreditkarte:
customer_ID = Kundenidentifizierung:
# Panels
shopping_cart = " Kredit "
customer = " Kunden "
# Buttons
purchase = Kaufen
clear = Zur?cksetzen
# Messages
invalid_value = Ung?ltiger Wert
cannot_send = Daten?bertragung zum Server nicht m?glich
no_lookup = Das Server l??t sich nicht zu finden
no_data = Keine Daten verf?gbar
no_ID = Keine Kundenidentifizierungen verf?gbar
no_server = Kein Zugang zu den Daten beim Server
----------------------------------
filename: Text_en_US.properties
----------------------------------
# Application title
title = Fruit 1.25 Each
# Labels
apples = Apples:
apples_mnemonic = A
peaches = Peaches:
pears = Pears:
total_tems = Total items:
total_cost = Total cost:
credit_card = Credit card:
customer_ID = Customer ID:
# Panels
shopping_cart = " Shopping cart "
customer = " Customer "
# Buttons
purchase = Purchase
clear = Clear
# Messages
invalid_value = Invalid value
cannot_send = Cannot send data to server
no_lookup = Cannot look up remote server object
no_data = No data available
no_ID = No customer IDs available
no_server = Cannot access data in server
----------------------------------
filename: Text_fr_FR.properties
----------------------------------
# Application title
title = Fruit 1.25 pi?ce
# Labels
apples = Pommes:
peaches = P?ches:
pears = Poires:
total_tems = Partial total:
total_cost = Prix total:
credit_card = Carte de Cr?dit:
customer_ID = Num?ro de client:
# Panels
shopping_cart = " Carte de pi?ce "
customer = " Client "
# Buttons
purchase = Achetez
clear = R?initialisez
# Messages
invalid_value = Valeur incorrecte
cannot_send = Les donn?es n'ont pu ?tre envoy?es au serveur
no_lookup = Acc?s impossible ? l'objet du serveur distant [remote server
object]
no_data = Aucune donn?e disponible
no_ID = Identifiant du client indisponible
no_server = Acc?s aux donn?es du serveur impossible
==========================================================================To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".