Sample code |
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.*;
import org.jvnet.substance.SubstanceDefaultListCellRenderer;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.theme.*;
/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#addMixedTheme(org.jvnet.substance.theme.SubstanceMixTheme)}
* API.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#addMixedTheme(org.jvnet.substance.theme.SubstanceMixTheme)
*/
public class AddMixedTheme1 extends JFrame {
/**
* Creates the main frame for <code>this</code> sample.
*/
public AddMixedTheme1() {
super("Add mixed themes");
this.setLayout(new BorderLayout());
final JPanel panel = new JPanel(new FlowLayout());
final JComboBox cb = new JComboBox(new Vector<ThemeInfo>(
SubstanceLookAndFeel.getAllThemes().values()));
cb.setRenderer(new SubstanceDefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
ThemeInfo ti = (ThemeInfo) value;
return super
.getListCellRendererComponent(list, ti
.getDisplayName(), index, isSelected,
cellHasFocus);
}
});
panel.add(new JLabel("All themes:"));
panel.add(cb);
this.add(panel, BorderLayout.CENTER);
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JButton addMixedTheme = new JButton(
"Add \"Aqua & Bottle Green\" theme");
addMixedTheme.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
addMixedTheme.setEnabled(false);
// add one mixed theme
SubstanceLookAndFeel
.addMixedTheme(new SubstanceMixTheme(
new SubstanceAquaTheme(),
new SubstanceBottleGreenTheme()));
// reset the combobox model to all available Substance
// themes
cb.setModel(new DefaultComboBoxModel(
new Vector<ThemeInfo>(SubstanceLookAndFeel
.getAllThemes().values())));
}
});
}
});
controls.add(addMixedTheme);
this.add(controls, BorderLayout.SOUTH);
this.setSize(400, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* The main method for <code>this</code> sample. The arguments are
* ignored.
*
* @param args
* Ignored.
* @throws Exception
* If some exception occured. Note that there is no special
* treatment of exception conditions in <code>this</code>
* sample code.
*/
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new SubstanceLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new AddMixedTheme1().setVisible(true);
}
});
}
}
The screenshot below shows the list of all available themes in
the default state:
The screenshot below shows the list of all available themes after this
API has been called to add a mixed Aqua / Bottle Green theme:
|