我自己的毕业项目是用swing做的,天天看着默认的Metal风格的样式实在审美疲劳,烦死了。决定改几个外观,也好改变心情好让我继续开发。
记录一下代码。哈哈。
// style manager.
private void styleManage(JMenuBar menubar) { // TODO Auto-generated method stub
JMenu styleMenu = new JMenu("Style"); ButtonGroup bgroup = new ButtonGroup(); String styleNow = UIManager.getLookAndFeel().getName(); for (Iterator it = STYLE.keySet().iterator(); it.hasNext();) { // String styleName = STYLE.getProperty((String) it.next());
final String radioItemTitle = (String) it.next(); JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem( radioItemTitle); styleMenu.add(radioItem); bgroup.add(radioItem); if (styleNow.equals(radioItemTitle)) { radioItem.setSelected(true); } radioItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub
// System.err.println(e.getSource());
String styleNow = UIManager.getLookAndFeel().getName(); TraceClientGUIJFrame mainFrame = TraceClientGUIJFrame.this; if (styleNow.equals(radioItemTitle) == false) { try { UIManager.setLookAndFeel(mainFrame.STYLE .getProperty(radioItemTitle)); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(mainFrame, ex .getClass().getName()); return; } SwingUtilities.updateComponentTreeUI(mainFrame); } }
}); } menubar.add(styleMenu); }
private static Properties STYLE = new Properties();
static { // first we need add system default LookAndFeels.
UIManager.LookAndFeelInfo[] infos = UIManager .getInstalledLookAndFeels(); for (int i = 0; i < infos.length; i++) { STYLE.setProperty(infos[i].getName(), infos[i].getClassName()); } // then we add third-party LookAndFeels. if they exist.
};
|
这段代码,只记录了怎么在系统默认支持的皮肤中切换,对于怎么加入第三方的皮肤外观还不是很清楚。但愿就是添加jar包就可以了。但是可能没这么简单。以后再学。
阅读(677) | 评论(0) | 转发(0) |