图形界面系列教材 (十四)- Swing 皮肤 Look And Feel

 

Java提供了非常便捷的方式切换界面风格

步骤1:设置皮肤

步骤 1 : 设置皮肤

只需要提供一句代码

javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");


就可以把所有的组件切换成不同的风格。

注: 这句话需要加在最前面,如果已经创建了界面,再加这个有时候不能正常起作用。

在右侧的附件里提供了各种皮肤,以及皮肤对应的jar包的下载

设置皮肤

package gui;

  

import javax.swing.JButton;

import javax.swing.JFrame;

  

public class TestGUI {

    public static void main(String[] args) {

        //设置皮肤 

        setLookAndFeel();

 

        JFrame f = new JFrame("LoL");

        f.setSize(400300);

        f.setLocation(200200);

        f.setLayout(null);

        JButton b = new JButton("一键秒对方基地挂");

        b.setBounds(505028030);

  

        f.add(b);

        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  

        f.setVisible(true);

    }

  

    private static void setLookAndFeel() {

        try {

          javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.fast.FastLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");

//          javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel"); 

        catch (Exception e) {

            e.printStackTrace();

            // handle exception

        }

  

    }

}


更多内容,点击了解: https://how2j.cn/k/gui/gui-lookandfeel/411.html

posted @ 2020-03-27 09:24  Lan_ht  阅读(293)  评论(0编辑  收藏  举报