1.change forSubstance L&F
必须包裹成invokeLater()
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
}
// rest of your code
}
});
}
2.最好是这个图,以他们的名字称呼皮肤
( SubstanceLookAndFeel.setSkin(new BusinessBlueSteelSkin());
)
或者
( UIManager.setLookAndFeel(new org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel());
)
基里尔的代码示例
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import org.pushingpixels.substance.api.DecorationAreaType;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.BusinessBlueSteelSkin;
/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#getDecorationType(java.awt.Component)} API called
* on different components.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#getDecorationType(java.awt.Component)
*/
public class GetDecorationType extends JFrame {
private static final long serialVersionUID = 1L;
/**
* Creates the main frame for <code>this</code> sample.
*/
public GetDecorationType() {
super("Get decoration type");
this.setLayout(new BorderLayout());
final JTabbedPane tabs = new JTabbedPane();
SubstanceLookAndFeel.setDecorationType(tabs, DecorationAreaType.HEADER);
JPanel tab1 = new JPanel(new FlowLayout());
tab1.add(new JTextField("sample"));
final JComboBox combo = new JComboBox(new Object[]{"sample"});
tab1.add(combo);
SubstanceLookAndFeel.setDecorationType(tab1, DecorationAreaType.GENERAL);
JPanel tab2 = new JPanel(new FlowLayout());
tab2.add(new JTextField("sample2"));
tab2.add(new JComboBox(new Object[]{"sample2"}));
SubstanceLookAndFeel.setDecorationType(tab2, DecorationAreaType.GENERAL);
tabs.addTab("tab1", tab1);
tabs.addTab("tab2", tab2);
this.add(tabs, BorderLayout.CENTER);
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton getTypes = new JButton("Get types");
getTypes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DecorationAreaType tabsType = SubstanceLookAndFeel.getDecorationType(tabs);
DecorationAreaType comboType = SubstanceLookAndFeel.getDecorationType(combo);
JOptionPane.showMessageDialog(GetDecorationType.this,
"Tabbed pane: " + tabsType.getDisplayName() + "\n" + "Combo box: " + comboType.getDisplayName());
}
});
}
});
controlPanel.add(getTypes);
this.add(controlPanel, 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.
*/
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SubstanceLookAndFeel.setSkin(new BusinessBlueSteelSkin());
UIManager.put("TabbedPane.contentOpaque", Boolean.TRUE);
new GetDecorationType().setVisible(true);
}
});
}
}