外观不能改变
为什么在Metal Motif Windows之间选择,外观完全一样,毫无变化照书本例子,书本里也给出三种外观为什么我试的不行呢import java.awt.*;import javax.swing.*;import java.awt.event.*;public class LookandFeel extends JFrame{ JRadioButton b1=new JRadioButton("Metal"), b2=new JRadioButton("Motif"), b3=new JRadioButton("Windows"); public LookandFeel() { super("Swing application"); Container contentPane=getContentPane(); contentPane.add(new Panel(),BorderLayout.CENTER); } public static void main(String args[]) { final JFrame f=new LookandFeel(); f.setBounds(100,100, 300, 300); f.setVisible(true); f.setDefaultCloseOperation(DISPOSE_ON_CLOSE); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } class Panel extends JPanel implements ActionListener { public Panel() { add(new JButton("JButton")); add(new JTextField("JTextField")); add(new JCheckBox("JCheckBox")); add(new JRadioButton("JRadioButton")); add(new JLabel("JLabel")); add(new JList(new String[]{ "JList Item 1","JList Item 2","JList Item 3"})); add(new JScrollBar(SwingConstants.HORIZONTAL)); ButtonGroup group=new ButtonGroup(); group.add(b1); group.add(b2); group.add(b3); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); add(b1); add(b2); add(b3); } public void actionPerformed(ActionEvent e) { JRadioButton src=(JRadioButton)e.getSource(); try { if((JRadioButton)e.getSource()==b1) UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookandFeel"); else if((JRadioButton)e.getSource()==b2) UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookandFeel"); else if((JRadioButton)e.getSource()==b3) UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookandFeel"); } catch (Exception ex) { } SwingUtilities.updateComponentTreeUI(getContentPane()); } } } 搜索更多相关的解决方案:
外观
----------------解决方案--------------------------------------------------------
为什么在Metal Motif Windows之间选择,外观完全一样,毫无变化
照书本例子,书本里也给出三种外观
为什么我试的不行呢
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class LookandFeel extends JFrame
{
JRadioButton b1=new JRadioButton("Metal"),
b2=new JRadioButton("Motif"),
b3=new JRadioButton("Windows");
public LookandFeel()
{
super("Swing application");
Container contentPane=getContentPane();
contentPane.add(new Panel(),BorderLayout.CENTER);
}
public static void main(String args[])
{
final JFrame f=new LookandFeel();
f.setBounds(100,100, 300, 300);
f.setVisible(true);
f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
class Panel extends JPanel implements ActionListener
{
public Panel()
{
add(new JButton("JButton"));
add(new JTextField("JTextField"));
add(new JCheckBox("JCheckBox"));
add(new JRadioButton("JRadioButton"));
add(new JLabel("JLabel"));
add(new JList(new String[]{
"JList Item 1","JList Item 2","JList Item 3"}));
add(new JScrollBar(SwingConstants.HORIZONTAL));
ButtonGroup group=new ButtonGroup();
group.add(b1);
group.add(b2);
group.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(b1);
add(b2);
add(b3);
}
public void actionPerformed(ActionEvent e)
{
JRadioButton src=(JRadioButton)e.getSource();
try
{
if((JRadioButton)e.getSource()==b1)
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookandFeel");
else if((JRadioButton)e.getSource()==b2)
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookandFeel");
else if((JRadioButton)e.getSource()==b3)
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookandFeel");
} catch (Exception ex)
{
}
SwingUtilities.updateComponentTreeUI(getContentPane());
}
}
}
----------------解决方案--------------------------------------------------------
这个例子我也做了。我想应该用到了Toolkit 这个类
----------------解决方案--------------------------------------------------------
原帖由 tgnian 于 2007-11-25 03:00 发表 [url=http://bbs.bc-cn.net/redirect.php?goto=findpost&pid=1113453&ptid=188183][/url] 为什么在Metal Motif Windows之间选择,外观完全一样,毫无变化照书本例子??,书本里也给出三种外观为什么我试的不行呢 import java.awt.*; import javax.swing.*; import java.awt.event.*; public class LookandFeel ...
因为lz拼写错了;
MetalLookandFeel -> MetalLookAndFeel
MotifLookandFeel- > MotifLookAndFeel
WindowsLookandFeel -> WindowsLookAndFeel
----------------解决方案--------------------------------------------------------
谢谢了
----------------解决方案--------------------------------------------------------
又是一个细节问题哦
----------------解决方案--------------------------------------------------------