设置JButton外观和感觉到awt.Buttons的外观

时间:2012-11-30 00:17:04

标签: java swing awt look-and-feel

如何让这个JButton看起来像一个awt.Button?

JButton button = new JButton("bob");
button.setUI(???????);

1 个答案:

答案 0 :(得分:3)

以下是三个独立的ui Lookandfeel选项

UIManager.setLookAndFeel (“java.awt.swing.plaf.metal.MetalLookAndFeel” ) ;  
SwingUtilities.updateComponentTreeUI ( this ) ;
UIManager.setLookAndFeel (“java.awt.swing.plaf.windows.WindowsLookAndFeel” ) ;   
SwingUtilities.updateComponentTreeUI ( this ) ;
UIManager.setLookAndFeel (“java.awt.swing.plaf.motif.MotifLookAndFeel” ) ; 
SwingUtilities.updateComponentTreeUI ( this ) ;

如果您想在机器上找到已安装的外观和感觉:

//Get Installed look and Feels
import javax.swing.UIManager;

public class InstalledLookandFeels {
public static void main(String args[]) {
    UIManager.LookAndFeelInfo laf[] = UIManager.getInstalledLookAndFeels();
    for (int i = 0, n = laf.length; i < n; i++) {
        System.out.print("LAF Name: " + laf[i].getName() + "\t");
        System.out.println("  LAF Class name: " + laf[i].getClassName());
    }
    System.exit(0);
  }
}