zoukankan      html  css  js  c++  java
  • java 切换不同的显示风格

    简介

    java 切换不同的显示风格

    code

    import java.awt.*;
    
    import javax.swing.*;
    
    public class ImageTest {
        public static void main(String[] args) {
            EventQueue.invokeLater(() -> {
                JFrame frame = new PlafFrame();
                frame.setTitle("ImageTest");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            });
            ;
        }
    }
    
    
    /*
     * @Author: your name
     * @Date: 2020-10-29 10:15:01
     * @LastEditTime: 2020-10-29 10:22:43
     * @LastEditors: Please set LastEditors
     * @Description: In User Settings Edit
     * @FilePath: /java/PlafFrame.java
     */
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    
    public class PlafFrame extends JFrame {
        private JPanel buttonPanel;
    
        public PlafFrame() {
            buttonPanel = new JPanel();
    
            UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
            for (UIManager.LookAndFeelInfo info : infos) {
                makeButton(info.getName(), info.getClassName());
            }
            add(buttonPanel);
            pack();
        }
    
        private void makeButton(String name, String className) {
            // add button to panel
    
            javax.swing.JButton button = new JButton(name);
            buttonPanel.add(button);
    
            // set button action
    
            button.addActionListener(event -> {
                try {
                    UIManager.setLookAndFeel(className);
                    SwingUtilities.updateComponentTreeUI(this);
                    pack();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    }
    
    

    image

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    matplotlib数据可视化之柱形图
    xpath排坑记
    Leetcode 100. 相同的树
    Leetcode 173. 二叉搜索树迭代器
    Leetcode 199. 二叉树的右视图
    Leetcode 102. 二叉树的层次遍历
    Leetcode 96. 不同的二叉搜索树
    Leetcode 700. 二叉搜索树中的搜索
    Leetcode 2. Add Two Numbers
    Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13895317.html
Copyright © 2011-2022 走看看