Usage

Top  Previous  Next

 

TableResourceManager is a class that facilitates the retrieval of resource bundle strings. The text strings on the various UI components of our library are retrieved with TableResourceManager's method:

 

public static final String getString(String resourceKey);

 

By default, at startup, the ResourceBundle corresponding to the default locale is instantiated. However, you can also assign the ResourceBundle that will be used with the methods:

 

public static void setResourceBundle(ResourceBundle resource);

public static void setResourceBundle(String resource);

public static void setResourceBundle(String resource, java.util.Locale locale);

 

You can also retrieve the current ResourceBundle with:

 

public static ResourceBundle getResourceBundle();

 

The components that make use of the resource bundle can also be reinitialized with new property values when their UI is updated. This is extremely useful for dynamically changing languages, without having to reload the whole application. The component's text will change to the new value if the TableResourceManager.updateComponents() method returns true. This is the default behaviour. You can change this value by calling:

 

public static void setUpdateComponents(boolean update);

 

In order to update the UI of an entire component (container, frame etc), you can use the Swing utility method SwingUtilities.updateComponentTreeUI(Component c).

 

Example: Change the language from English (default) to French.

 

Assuming that frame is the instance of the application's frame.

 

TableResourceManager.setResourceBundle("TableLibraryBundle_fr");

TableResourceManager.setUpdateComponents(true);

SwingUtilities.updateComponentTreeUI(frame);

 

Alternatively, having an instance of a component inside your application's frame, you can use javax.swing.JOptionPane.getFrameForComponent(component) to get to the frame. e.g. :

 

Frame frame = JOptionPane.getFrameForComponent(component);

SwingUtilities.updateComponentTreeUI(frame);

 

Notes:

1. The French resource bundle in this example must be created by the developer.

2. If TableResourceManager.updateComponents() is false, the language of the components will not be altered.