Swing 改变观感 UIManager.setLookAndFeel UIManager.update.updateLookAndFeel(..)
2009-02-27 09:42
281 查看
改变观感:
方法一:
在jre/lib下的swing.properties中,将swing.defaultlaf设为:
Swing.defaultlaf = com.sun.java.swing.plaf.motif.MotifLookAndFeel
注:
在属性文件中,以#开头的行被省略,所以可以保留原来的观感,便于修改。这种方式必须重启程序。
方法二:
动态的改变观感。
注:
嵌套类中This发生混淆时,要使用ClassName.this来指明。
关键是如下两条:
UIManager.setLookAndFeel(lookName);
根据观感的名字设定其观感。
SwingUtilities.updateComponentTreeUI(LookAndFeel.this);
给定一个组件后,更新所有的组件。
例子:
/**
*LookAndFeel.java
* Created on 9:01:54 AM Feb 27, 2009
*@author Quasar063501
*@version 0.1
*
*/
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 LookAndFeel extends JFrame {
private JPanel buttonPanel = null;
public void launchFrame() {
this.setSize(200,300);
buttonPanel = new JPanel();
//的到所有安装的观感
UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
//new for
for(UIManager.LookAndFeelInfo info : infos) {
makeButton(info.getName(),info.getClassName());
}
this.add(buttonPanel);
this.setVisible(true);
}
private void makeButton(String bName, final String lookName) {
JButton b = new JButton(bName);
buttonPanel.add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
UIManager.setLookAndFeel(lookName);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(LookAndFeel.this);
}
});
}
public static void main(String[] args) {
new LookAndFeel().launchFrame();
}
}
相关类:
javax.swing.UIManager
javax.seing.UIManager.LookAndFeelInfo
方法一:
在jre/lib下的swing.properties中,将swing.defaultlaf设为:
Swing.defaultlaf = com.sun.java.swing.plaf.motif.MotifLookAndFeel
注:
在属性文件中,以#开头的行被省略,所以可以保留原来的观感,便于修改。这种方式必须重启程序。
方法二:
动态的改变观感。
注:
嵌套类中This发生混淆时,要使用ClassName.this来指明。
关键是如下两条:
UIManager.setLookAndFeel(lookName);
根据观感的名字设定其观感。
SwingUtilities.updateComponentTreeUI(LookAndFeel.this);
给定一个组件后,更新所有的组件。
例子:
/**
*LookAndFeel.java
* Created on 9:01:54 AM Feb 27, 2009
*@author Quasar063501
*@version 0.1
*
*/
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 LookAndFeel extends JFrame {
private JPanel buttonPanel = null;
public void launchFrame() {
this.setSize(200,300);
buttonPanel = new JPanel();
//的到所有安装的观感
UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
//new for
for(UIManager.LookAndFeelInfo info : infos) {
makeButton(info.getName(),info.getClassName());
}
this.add(buttonPanel);
this.setVisible(true);
}
private void makeButton(String bName, final String lookName) {
JButton b = new JButton(bName);
buttonPanel.add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
UIManager.setLookAndFeel(lookName);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(LookAndFeel.this);
}
});
}
public static void main(String[] args) {
new LookAndFeel().launchFrame();
}
}
相关类:
javax.swing.UIManager
javax.seing.UIManager.LookAndFeelInfo
相关文章推荐
- 基于AWT、Swing的GUI程序 - 改变观感
- 基于AWT、Swing的GUI程序 - 改变观感
- Java应用swing改变观感
- Java应用swing改变观感(补充)【转】
- JAVA Swing 改变标题栏左上角默认咖啡图标
- Swing 观感设置(LookAndFeel)(转)
- Java 改变观感
- 观感默认设置相关文件swing.properties的设置问题
- 改变swing的风格
- Swing容器中在jTable中添加combobox下拉框时,有关一个下拉框值改变,另一个下拉框值随之改变的方法
- Swing组件JList的列表数据修改了,如何通知JList改变显
- Java swing中改变jar文件的标题栏图标
- java Swing 滚动滑轮改变图片大小
- 我遇到的java笔试题->Swing组件JList的列表数据修改了,如何通知JList改变显示?
- Java:观感改变以及两个JRE文件区别
- Java Swing 变换观感小程序 Metal观感 Nimbus观感 Windows观感 Java核心技术
- swing中动态改变图片
- Java swing中改变jar文件的标题栏图标
- Swing中改变Table的column大小
- Java改变程序观感