i18n-swing
i18n-swing provides drop-in replacements for every standard Swing component. Each Resourceful* class extends its standard Swing counterpart and automatically re-applies all localizable properties on the Event Dispatch Thread when the application locale changes.
Artifact: dev.javai18n:i18n-swing · Requires: Java 17+ · View Javadoc →
<dependency> <groupId>dev.javai18n</groupId> <artifactId>i18n-swing</artifactId> <version>1.2.2</version></dependency>module my.module { requires dev.javai18n.swing;}Quick start
Section titled “Quick start”1. Extend a Localizable container
public class MyFrame extends LocalizableJFrame { static { MyModuleRegistrar.ensureRegistered(); }
@Override public Locale[] getAvailableLocales() { return new Locale[]{ Locale.ROOT, Locale.FRANCE }; }}2. Define a resource bundle
MyFrameBundle.json:
{ "okButton": { "type": "dev.javai18n.swing.AbstractButtonPropertyBundle", "Text": "OK", "Mnemonic": 79 }}MyFrameBundle_fr.json:
{ "okButton": { "type": "dev.javai18n.swing.AbstractButtonPropertyBundle", "Text": "D'accord", "Mnemonic": 68 }}3. Create Resourceful components
MyFrame frame = MyFrame.create();Resource okResource = new Resource(frame, "okButton");ResourcefulJButton okButton = ResourcefulJButton.create(okResource);
// Switch the entire UI to French — every attached component updates on the EDTframe.setBundleLocale(Locale.FRANCE);Localizable containers
Section titled “Localizable containers”These classes serve as the locale-event source for all Resourceful components they own.
| Class | Extends | Notes |
|---|---|---|
LocalizableJFrame | JFrame | Standard application frame; bundle key "windowProperties" uses FramePropertyBundle |
LocalizableJDialog | JDialog | Modal or non-modal dialog; bundle key "windowProperties" uses FramePropertyBundle |
LocalizableJWindow | JWindow | Undecorated window; bundle key "windowProperties" uses WindowPropertyBundle |
Resourceful components
Section titled “Resourceful components”The base set of localized properties for every Resourceful component is: name, tooltip, font, accessible name, accessible description (from JComponentPropertyBundle).
Buttons and toggles
| Class | Extends | Additional localized properties |
|---|---|---|
ResourcefulJButton | JButton | text, label, mnemonic, 7 icon types |
ResourcefulJCheckBox | JCheckBox | text, label, mnemonic, 7 icon types |
ResourcefulJRadioButton | JRadioButton | text, label, mnemonic, 7 icon types |
ResourcefulJToggleButton | JToggleButton | text, label, mnemonic, 7 icon types |
Menus
| Class | Extends | Additional localized properties |
|---|---|---|
ResourcefulJMenu | JMenu | text, label, mnemonic, 7 icon types |
ResourcefulJMenuBar | JMenuBar | — |
ResourcefulJMenuItem | JMenuItem | text, label, mnemonic, 7 icon types |
ResourcefulJCheckBoxMenuItem | JCheckBoxMenuItem | text, label, mnemonic, 7 icon types |
ResourcefulJRadioButtonMenuItem | JRadioButtonMenuItem | text, label, mnemonic, 7 icon types |
ResourcefulJPopupMenu | JPopupMenu | — |
ResourcefulJPopupMenuSeparator | JPopupMenu.Separator | — |
Text components
| Class | Extends |
|---|---|
ResourcefulJTextField | JTextField |
ResourcefulJTextArea | JTextArea |
ResourcefulJEditorPane | JEditorPane |
ResourcefulJTextPane | JTextPane |
ResourcefulJPasswordField | JPasswordField |
ResourcefulJFormattedTextField | JFormattedTextField |
Data and selection
| Class | Extends | Additional localized properties |
|---|---|---|
ResourcefulJComboBox | JComboBox | item values (string array) |
ResourcefulJList | JList | — |
ResourcefulJSpinner | JSpinner | — |
ResourcefulJSlider | JSlider | — |
ResourcefulJTree | JTree | — |
ResourcefulJTable | JTable | — |
ResourcefulJTableHeader | JTableHeader | — |
ResourcefulJProgressBar | JProgressBar | progress string |
ResourcefulJScrollBar | JScrollBar | — |
ResourcefulJColorChooser | JColorChooser | — |
ResourcefulJFileChooser | JFileChooser | dialog title, approve button text/tooltip |
Panes and containers
| Class | Extends | Additional localized properties |
|---|---|---|
ResourcefulJPanel | JPanel | — |
ResourcefulJScrollPane | JScrollPane | — |
ResourcefulJSplitPane | JSplitPane | — |
ResourcefulJTabbedPane | JTabbedPane | per-tab title, tooltip, icon |
ResourcefulJInternalFrame | JInternalFrame | title, frame icon |
ResourcefulJLayeredPane | JLayeredPane | — |
ResourcefulJDesktopPane | JDesktopPane | — |
ResourcefulJDesktopIcon | JDesktopIcon | — |
ResourcefulJRootPane | JRootPane | — |
ResourcefulJViewport | JViewport | — |
ResourcefulJOptionPane | JOptionPane | dialog title, button option labels |
Layout helpers
| Class | Extends | Additional localized properties |
|---|---|---|
ResourcefulBox | Box | — |
ResourcefulBoxFiller | Box.Filler | — |
ResourcefulJLabel | JLabel | text, mnemonic, icon, disabled icon |
ResourcefulJSeparator | JSeparator | — |
ResourcefulJToolBar | JToolBar | — |
ResourcefulJToolBarSeparator | JToolBar.Separator | — |
ResourcefulJToolTip | JToolTip | tip text |
Spinner editors
| Class | Extends |
|---|---|
ResourcefulJSpinnerDefaultEditor | JSpinner.DefaultEditor |
ResourcefulJSpinnerDateEditor | JSpinner.DateEditor |
ResourcefulJSpinnerNumberEditor | JSpinner.NumberEditor |
ResourcefulJSpinnerListEditor | JSpinner.ListEditor |
Utility menu items
| Class | Extends | Description |
|---|---|---|
LocaleJMenuItem | ResourcefulJRadioButtonMenuItem | Displays a locale name; sets the application locale when selected; shows a radio-button check mark for the active locale |
LookAndFeelJMenuItem | ResourcefulJMenuItem | Displays a Look and Feel name; applies it when selected |
Property bundles
Section titled “Property bundles”| Bundle | Extends | Fields |
|---|---|---|
ComponentPropertyBundle | — | name, font, accessible name, accessible description |
JComponentPropertyBundle | ComponentPropertyBundle | + tooltip |
AbstractButtonPropertyBundle | JComponentPropertyBundle | + text, label, mnemonic, icon, pressed, selected, disabled, disabled-selected, rollover, rollover-selected icons |
JLabelPropertyBundle | JComponentPropertyBundle | + text, mnemonic, icon, disabled icon |
JComboBoxPropertyBundle | JComponentPropertyBundle | + values (string array) |
JProgressBarPropertyBundle | JComponentPropertyBundle | + progress string |
JInternalFramePropertyBundle | JComponentPropertyBundle | + title, frame icon |
JTabbedPaneTabPropertyBundle | — | tab title, tab tooltip, tab icon (one entry per tab) |
JOptionPanePropertyBundle | JComponentPropertyBundle | + title, options (string array) |
JFileChooserPropertyBundle | JComponentPropertyBundle | + dialog title, approve button text/tooltip |
JToolTipPropertyBundle | JComponentPropertyBundle | + tip text |
WindowPropertyBundle | ComponentPropertyBundle | + icon images (list) |
FramePropertyBundle | WindowPropertyBundle | + title |
Testing notes
Section titled “Testing notes”LocalizationDelegate initializes its locale from Locale.getDefault() at construction time. Maven Surefire’s -Duser.language flag does not change Locale.getDefault() in the forked JVM — it is propagated via System.setProperty() after the JVM’s default locale has already been set.
Rule: In any test that asserts specific string values from a bundle, always pin the locale explicitly before constructing the Localizable object:
TestComponentSource source = TestComponentSource.create();// create() calls setBundleLocale(Locale.ROOT) immediately after construction
ResourceBundle rb = ResourceBundle.getBundle( "com.example.MyFrameBundle", Locale.ROOT); // always pass explicit localeSee the full guide for the complete explanation.