1

my run.bat:

@echo off
@title test
java -Dfile.encoding=Cp1252 -classpath bin;lib/libs.jar;lib/substance-6.0.jar;lib/trident-1.2.jar; Loader
pause

my frame:

void openFrame() {
        try {
         UIManager.setLookAndFeel("org.pushingpixals.substance.api.skin.SubstanceTwilightLookAndFeel"); 
            JFrame.setDefaultLookAndFeelDecorated(true);
             JDialog.setDefaultLookAndFeelDecorated(true);
        } catch (Throwable e) {
            e.getStackTrace();
        }
               appletFrame = new JFrame(Settings.serverName);
               appletFrame.setLayout(new BorderLayout());
    appletFrame.setDefaultCloseOperation(3);
    appletPanel.setLayout(new BorderLayout());
    appletPanel.add(this);
    appletPanel.setPreferredSize(new Dimension(765, 504));
    appletFrame.getContentPane().add(appletPanel, "Center");
    appletFrame.pack();
    appletFrame.setLocationRelativeTo(null);
    appletFrame.setVisible(true);

I did this but for some reason the theme doesnt change. What seems to be the problem? I got the correct substance, and trident, yet it does not change.

3
  • What exactly you meant by appletFrame ? Never use such terms which look obnoxious, it can either be a JApplet or JFrame but not both :-)
    – nIcE cOw
    Jun 22, 2012 at 2:48
  • @lhballoti : If not, than it's a nice catch :-)
    – nIcE cOw
    Jun 22, 2012 at 3:20
  • lots of mistakes here more in Modifying the Look and Feel
    – mKorbel
    Jun 22, 2012 at 8:00

1 Answer 1

1

1.change for Substance L&F must be wrapped into 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.better would be this figure, to call skin by their name

(SubstanceLookAndFeel.setSkin(new BusinessBlueSteelSkin());)

or

(UIManager.setLookAndFeel(new org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel());)

code example by Kirill

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);
            }
        });
    }
}
3
  • +!, nice working example. Substance LookAndFeel is real good :-)
    – nIcE cOw
    Jun 22, 2012 at 12:36
  • Thanks, but it didnt work :/, I tried with an older version of substance look and feel and it worked with the code I showed you. Although the older versions of substance look and feel have really ugly themes, and pushingpixal's substances have great nice looking theme. Just those dont seem to work for me.
    – 0x29A
    Jun 22, 2012 at 15:34
  • eerrrghtt what did you talking about
    – mKorbel
    Jun 22, 2012 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.