Sample code |
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.utils.SubstanceCoreUtilities;
/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#CAN_BE_PINNED} client property.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#CAN_BE_PINNED
*/
public class CanBePinned extends JFrame {
/**
* Creates the main frame for <code>this</code> sample.
*/
public CanBePinned() {
super("Can be pinned");
this.setLayout(new BorderLayout());
// create a desktop pane with one internal frame
JDesktopPane jdp = new JDesktopPane();
final JInternalFrame jif = new JInternalFrame();
jif.setBounds(10, 10, 300, 120);
jif.setLayout(new FlowLayout(FlowLayout.CENTER));
jif.add(new JButton("test"));
jdp.add(jif);
jif.setMaximizable(true);
jif.setIconifiable(true);
jif.setClosable(true);
jif.setVisible(true);
this.add(jdp, BorderLayout.CENTER);
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JCheckBox canBePinned = new JCheckBox("can be pinned");
canBePinned.setSelected(SubstanceCoreUtilities.canBePinned(jif));
canBePinned.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// based on the checkbox selection, mark the internal
// frame as can be pinned
jif.putClientProperty(
SubstanceLookAndFeel.CAN_BE_PINNED, canBePinned
.isSelected() ? null : Boolean.FALSE);
repaint();
}
});
}
});
controls.add(canBePinned);
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 CanBePinned().setVisible(true);
}
});
}
}
The screenshot below shows the application frame with an internal frame
in default state (pin button present):
The screenshot below shows the same internal frame
marked with this property set to Boolean.FALSE
(pin button is not showing):
|