package looksAndFeels; import javax.swing.*; import javax.swing.UIManager.*; import java.awt.event.*; public class ThemeChanger extends JFrame { ThemeChanger __instance; public ThemeChanger() { super("Swing Theme Changer"); __instance = this; this.setSize(400, 200); JMenuBar appMenu = new JMenuBar(); appMenu.add(makeLaFMenu()); this.setJMenuBar(appMenu); this.setVisible(true); } private JMenu makeLaFMenu() { JMenuItem tempItem; JMenu lafMenu = new JMenu("Supported Themes"); LookAndFeelInfo[] supportedLAFs = UIManager.getInstalledLookAndFeels(); for (int ii = 0; ii < supportedLAFs.length; ii++) { LookAndFeelInfo currentLAF = supportedLAFs[ii]; tempItem = new JMenuItem(currentLAF.getName()); tempItem.setActionCommand(currentLAF.getClassName()); tempItem.addActionListener(new myListener()); lafMenu.add(tempItem); } return lafMenu; } class myListener implements ActionListener { public void actionPerformed(ActionEvent event) { try { UIManager.setLookAndFeel(event.getActionCommand()); } catch (Exception e) { ; // No exceptions will happen (barring some unforeseen catastrophe), // because we only grabbed the supported LaF's. } SwingUtilities.updateComponentTreeUI(__instance); } } public static void main(String[] args) { new ThemeChanger(); } }
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
JMenu that switches between Swing LookAndFeel themes. (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Grep Rails log file targetin... in apache php mysql find awk email ruby rails time date perl regex shell http osx css python calendar google input html bash windows sql activerecord javascript java actionscript rubyonrails unix linux fixtures database textmate c text XSLT image string location xml swing copy xmlhttprequest array onload tags web url function math json io download parser imagemagick utf8 dos hash convert batch rectangle binary C++ map jpeg delicious series60 rexml camera zoom zope
» JavaScript: Changing an Elem... in apache php mysql find awk email ruby rails time date perl regex shell http osx css python calendar google input html bash windows sql activerecord javascript java actionscript rubyonrails unix linux fixtures database textmate c text XSLT image string location xml swing copy xmlhttprequest array onload tags web url function math json io download parser imagemagick utf8 dos hash convert batch rectangle binary C++ map jpeg delicious series60 rexml camera zoom zope
» Utilização de arquivo ... in java TempFile createTempFile
» Use Sun Java in Ubuntu Breezy in java ubuntu
» Print Hello in java
» Walk list of HTTP Request Pa... in java
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails