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 {
//設置觀感并更新組件
UIManager.setLookAndFeel(plafName);
SwingUtilities.updateComponentTreeUI(PlafFrame.this);
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException
| UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
}
});
}
}
相關文章
Springboot項目中定時任務的四種實現(xiàn)方式詳解
Spring的@Scheduled注解是一種非常簡單和便捷的實現(xiàn)定時任務的方式,通過在方法上添加@Scheduled注解,我們可以指定方法在特定的時間間隔或固定的時間點執(zhí)行,本文給大家介紹Springboot項目中定時任務的四種實現(xiàn)方式,感興趣的的朋友一起看看b2024-02-02Spring Boot集成springfox-swagger2構(gòu)建restful API的方法教程
這篇文章主要給大家介紹了關于Spring Boot集成springfox-swagger2構(gòu)建restful API的相關資料,文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編一起來學習學習吧。2017-06-06JavaEE中用response向客戶端輸出中文數(shù)據(jù)亂碼問題分析
這篇文章主要介紹了JavaEE中用response向客戶端輸出中文數(shù)據(jù)亂碼問題分析,需要的朋友可以參考下2014-10-10