java - 添加了新的 Pushpixal 主题,但没有变化

标签 java swing jframe look-and-feel substance

我的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

我的框架:

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);

我这样做了,但由于某种原因主题没有改变。似乎有什么问题?我得到了正确的物质和三叉戟,但它没有改变。

最佳答案

1.Substance 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);
            }
        });
    }
}

关于java - 添加了新的 Pushpixal 主题,但没有变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11149382/

相关文章:

java - 如何在 JComponent.revalidate 和 Container.validate 之间进行选择

java - 代码运行多次

java - 循环遍历n张 map

java - Jython 作为 Java 游戏的游戏内控制台

java - swing - 为什么要创建两个单独的盒子

java - 为什么这个 JPanel 不符合指定的大小?

java - IntelliJ IDEA - JScrollpane 中的 JPanel 未显示内容

java - 向 SQlite 插入行时 Android 应用程序崩溃?

java - 在 Java 中格式化大数字

java - JColorChooser:在样本面板中保存/恢复最近的颜色