Methods Summary |
---|
public java.lang.String[] | getAllThemeNames()Get the list of all known theme names. The returned values are
theme property names, not theme display names.
java.util.List names = resources.getStringList("themelist");
return (String[]) names.toArray(new String[names.size()]);
|
public java.lang.String | getDefaultThemeName()Get the name of the default theme, or null
return resources.getString("defaultTheme", null);
|
public java.lang.String | getDisplayName(java.lang.String themeName)Get the "display name" or label of the named theme
return resources.getString(themeName + ".name", null);
|
public javax.swing.JMenu | getThemeMenu()Get a JMenu that lists all known themes by display name and
installs any selected theme.
String[] names = getAllThemeNames();
String defaultName = getDefaultThemeName();
JMenu menu = new JMenu("Themes");
ButtonGroup buttongroup = new ButtonGroup();
for(int i = 0; i < names.length; i++) {
final String themeName = names[i];
String displayName = getDisplayName(themeName);
JMenuItem item = menu.add(new JRadioButtonMenuItem(displayName));
buttongroup.add(item);
if (themeName.equals(defaultName)) item.setSelected(true);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
setTheme(themeName);
}
});
}
return menu;
|
public void | setTheme(java.lang.String themeName)Look up the named theme, and apply it to the frame
// Look up the theme in the resource bundle
Theme theme = new Theme(resources, themeName);
// Make it the current theme
MetalLookAndFeel.setCurrentTheme(theme);
// Re-apply the Metal look-and-feel to install new theme
try { UIManager.setLookAndFeel(new MetalLookAndFeel()); }
catch(UnsupportedLookAndFeelException e) {}
// If the theme has an audio playlist, then set it
if (theme.playlist != null)
UIManager.put("AuditoryCues.playList", theme.playlist);
// Propagate the new l&f across the entire component tree of the frame
SwingUtilities.updateComponentTreeUI(frame);
|