Sample code |
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.*;
import org.jvnet.substance.SubstanceImageCreator;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.theme.SubstanceTheme;
import org.jvnet.substance.title.TitleButtonCallback;
import org.jvnet.substance.title.TitleButtonInfo;
/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#removeRootPaneCustomTitleButtons(JRootPane)} and
* {@link SubstanceLookAndFeel#setRootPaneCustomTitleButtons(JRootPane, java.util.List)}
* API.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#removeRootPaneCustomTitleButtons(JRootPane)
* @see SubstanceLookAndFeel#setRootPaneCustomTitleButtons(JRootPane,
* java.util.List)
*/
public class SetRemoveRootPaneCustomTitleButtons extends JFrame {
/**
* Creates the main frame for <code>this</code> sample.
*/
public SetRemoveRootPaneCustomTitleButtons() {
super("Root pane custom title buttons");
this.setLayout(new BorderLayout());
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
controls.add(new JLabel("Root pane custom title buttons"));
final JButton set = new JButton("Set");
final JButton remove = new JButton("Remove");
remove.setEnabled(false);
set.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// create info on two sample custom title buttons.
TitleButtonInfo tbInfo1 = new TitleButtonInfo();
tbInfo1.setActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
SetRemoveRootPaneCustomTitleButtons.this,
"Custom button 1 activated");
}
});
tbInfo1.setTooltipText("Tooltip for custom button 1");
tbInfo1.setButtonCallback(new TitleButtonCallback() {
public Icon getTitleButtonIcon(
SubstanceTheme currSubstanceTheme,
int iconMaxWidth, int iconMaxHeight) {
return new ImageIcon(SubstanceImageCreator.overlayEcho(
SubstanceImageCreator
.getArrow(9, 5, SwingConstants.WEST,
currSubstanceTheme), 1, 1));
}
});
TitleButtonInfo tbInfo2 = new TitleButtonInfo();
tbInfo2.setActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
SetRemoveRootPaneCustomTitleButtons.this,
"Custom button 2 activated");
}
});
tbInfo2.setTooltipText("Tooltip for custom button 2");
tbInfo2.setButtonCallback(new TitleButtonCallback() {
public Icon getTitleButtonIcon(
SubstanceTheme currSubstanceTheme,
int iconMaxWidth, int iconMaxHeight) {
return new ImageIcon(SubstanceImageCreator.overlayEcho(
SubstanceImageCreator
.getArrow(9, 5, SwingConstants.EAST,
currSubstanceTheme), 1, 1));
}
});
java.util.List<TitleButtonInfo> tbInfoList = new LinkedList<TitleButtonInfo>();
tbInfoList.add(tbInfo1);
tbInfoList.add(tbInfo2);
// set custom title buttons
SubstanceLookAndFeel.setRootPaneCustomTitleButtons(
getRootPane(), tbInfoList);
set.setEnabled(false);
remove.setEnabled(true);
}
});
remove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// remove custom title buttons
SubstanceLookAndFeel
.removeRootPaneCustomTitleButtons(getRootPane());
remove.setEnabled(false);
set.setEnabled(true);
}
});
controls.add(set);
controls.add(remove);
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 SetRemoveRootPaneCustomTitleButtons().setVisible(true);
}
});
}
}
The screenshot below shows application frame with default
title pane (no custom title buttons):
The screenshot below shows application frame after this API has been
called with information on two custom title buttons:
|