当前位置: 技术问答>java相关
记得在一本书上看到有一个文件可以改变swing的默认ui外观!!--那位大侠提醒一下!!
来源: 互联网 发布时间:2015-01-16
本文导语: 忘了那个文件是什么了!! under windows platform!! thanx! | 在JDK目录下的jrblib 目录里新增一个文件,文件名是swing.properties(在这个目录里还有许多其它的properties文件),内空如下 swing.defaultlaf=com...
忘了那个文件是什么了!!
under windows platform!!
thanx!
under windows platform!!
thanx!
|
在JDK目录下的jrblib 目录里新增一个文件,文件名是swing.properties(在这个目录里还有许多其它的properties文件),内空如下
swing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel
swing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel
|
一个例子:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class PlafPanel extends JPanel
implements ActionListener
{ public PlafPanel()
{ metalButton = new JButton("Metal");
motifButton = new JButton("Motif");
windowsButton = new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{ Object source = evt.getSource();
String plaf = "";
if (source == metalButton)
plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
else if (source == motifButton)
plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source == windowsButton)
plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
{ UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception e) {}
}
private JButton metalButton;
private JButton motifButton;
private JButton windowsButton;
}
class PlafFrame extends JFrame
{ public PlafFrame()
{ setTitle("PlafTest");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
Container contentPane = getContentPane();
contentPane.add(new PlafPanel());
}
}
public class PlafTest
{ public static void main(String[] args)
{ JFrame frame = new PlafFrame();
frame.show();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class PlafPanel extends JPanel
implements ActionListener
{ public PlafPanel()
{ metalButton = new JButton("Metal");
motifButton = new JButton("Motif");
windowsButton = new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{ Object source = evt.getSource();
String plaf = "";
if (source == metalButton)
plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
else if (source == motifButton)
plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source == windowsButton)
plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
{ UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception e) {}
}
private JButton metalButton;
private JButton motifButton;
private JButton windowsButton;
}
class PlafFrame extends JFrame
{ public PlafFrame()
{ setTitle("PlafTest");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
Container contentPane = getContentPane();
contentPane.add(new PlafPanel());
}
}
public class PlafTest
{ public static void main(String[] args)
{ JFrame frame = new PlafFrame();
frame.show();
}
}
|
加到Main中
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFell");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFell");
|
UIManager.setLookAndFeel(...)