java觀感示例分享
package com.hongyuan.gui;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class PlafTest {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
PlafFrame frame=new PlafFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class PlafFrame extends JFrame
{
private JPanel buttonPanel;
public PlafFrame(){
this.setTitle("PlafTest");
this.setSize(400, 300);
buttonPanel=new JPanel();
//查詢觀感并生成按鈕
UIManager.LookAndFeelInfo[] infos=UIManager.getInstalledLookAndFeels();
for(UIManager.LookAndFeelInfo info:infos){
makeButton(info.getName(),info.getClassName());
}
this.add(buttonPanel);
}
void makeButton(String name,final String plafName){
JButton button=new JButton(name);
buttonPanel.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
//設(shè)置觀感并更新組件
UIManager.setLookAndFeel(plafName);
SwingUtilities.updateComponentTreeUI(PlafFrame.this);
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException
| UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
}
});
}
}
相關(guān)文章
java線程安全鎖ReentrantReadWriteLock原理分析readLock
這篇文章主要為大家介紹了java線程安全鎖ReentrantReadWriteLock原理分析readLock,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10
JavaWeb?Servlet技術(shù)及其應(yīng)用實踐
這篇文章主要介紹了JavaWeb?Servlet技術(shù),Servlet指在服務(wù)器端執(zhí)行的一段Java代碼,可以接收用戶的請求和返回給用戶響應(yīng)結(jié)果,感興趣想要詳細了解可以參考下文2023-05-05
Springboot2.6.x高版本與Swagger2版本沖突問題解決方法
Spring Boot 2.6.x版本引入依賴?springfox-boot-starter?(Swagger?3.0) 后,啟動容器會報錯,本文就介紹一下Springboot2.6.x高版本與Swagger2版本沖突問題解決方法,感興趣的可以了解一下2022-04-04
SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實現(xiàn)
這篇文章主要介紹了SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-04-04

