import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.button.ClassicButtonShaper;
/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#setCurrentButtonShaper(org.jvnet.substance.button.SubstanceButtonShaper)}
* API.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#setCurrentButtonShaper(org.jvnet.substance.button.SubstanceButtonShaper)
*/
public class SetCurrentButtonShaper_Instance extends JFrame {
/**
* Creates the main frame for <code>this</code> sample.
*/
public SetCurrentButtonShaper_Instance() {
super("Set current button shaper");
this.setLayout(new BorderLayout());
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JButton changeButtonShaper = new JButton("Change button shaper");
changeButtonShaper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
changeButtonShaper.setEnabled(false);
// set new button shaper by instance
SubstanceLookAndFeel
.setCurrentButtonShaper(new ClassicButtonShaper());
repaint();
}
});
}
});
controls.add(changeButtonShaper);
JButton getShaperName = new JButton("Get current button shaper name");
getShaperName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
SetCurrentButtonShaper_Instance.this,
"Current button shaper name is "
+ SubstanceLookAndFeel
.getCurrentButtonShaperName());
}
});
controls.add(getShaperName);
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);
JDialog.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SetCurrentButtonShaper_Instance().setVisible(true);
}
});
}
}
The screenshot below shows application frame under default
button shaper (Standard). Note the rounded buttons:
The screenshot below shows the result of calling this API
with ClassicButtonShaper instance.
Note the almost rectangular buttons:
|