home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-09-15 | 2.4 KB | 90 lines |
- package com.symantec.itools.swing;
-
- import java.awt.*;
- import java.awt.event.*;
- import java.util.Vector;
- import com.sun.java.swing.*;
- import com.sun.java.swing.event.*;
-
- public class JLookAndFeelComboBox
- extends JComboBox
- implements ActionListener, Runnable
- {
- public JLookAndFeelComboBox()
- {
- super();
-
- setupInitialValues();
- refelectCurrentUI();
-
- addActionListener(this);
- }
-
- protected void setupInitialValues()
- {
- UIManager.LookAndFeelInfo[] lnfInfos = UIManager.getInstalledLookAndFeels();
- for (int i = 0;i < lnfInfos.length;i++)
- addItem(lnfInfos[i].getName());
- }
-
- protected void refelectCurrentUI()
- {
- String currLnFName = UIManager.getLookAndFeel().getName();
-
- UIManager.LookAndFeelInfo[] lnfInfos = UIManager.getInstalledLookAndFeels();
- for (int i = 0;i < lnfInfos.length;i++)
- {
- if (lnfInfos[i].getName().equals(currLnFName))
- {
- setSelectedIndex(i);
- break;
- }
- }
- }
-
- public void actionPerformed(ActionEvent actionEvent)
- {
- if (java.beans.Beans.isDesignTime())
- return;
-
- int selectedLnF = getSelectedIndex();
-
- UIManager.LookAndFeelInfo[] lnfInfos = UIManager.getInstalledLookAndFeels();
-
- try
- {
- UIManager.setLookAndFeel(lnfInfos[selectedLnF].getClassName());
- }
- catch(Exception e)
- {
- e.printStackTrace();
- refelectCurrentUI();
- }
-
- SwingUtilities.invokeLater(this);
- }
-
- public void run()
- {
- //Find top root pane
- JRootPane topRoot = SwingUtilities.getRootPane(this);
- if (topRoot != null)
- {
- while (true)
- {
- Container rootParent = topRoot.getParent();
- if (rootParent == null)
- break;
-
- JRootPane possibleRoot = SwingUtilities.getRootPane(rootParent);
- if (possibleRoot == null || possibleRoot == topRoot)
- break;
-
- topRoot = possibleRoot;
- }
-
- SwingUtilities.updateComponentTreeUI(topRoot);
- }
- }
- }
-