2012-08-10 168 views

回答

2

你可以设置一个JButton的背景图像,你可以看看这个:Swing Tutorial: JButton这表明使用new JButton(String text,ImageIcon imgIco)的创建具有ImageIconString一个JButton

要设置背景颜色和文字,你可以使用setBackground(Color c)setForeground(Color c)

或者只是定制外观和设置适当的支持Look and Feel然后change the color scheme/size etc of its components thier数以百计的事情感到配色方案您可以更改每个组件,详见this

定制退出最小化最大化工具栏按钮,这也可以通过外观(Custom design for Close/Minimize buttons on JFrame):

MetalWindows

import java.awt.BorderLayout; 
import javax.swing.*; 

public class FrameCloseButtonsByLookAndFeel { 

    FrameCloseButtonsByLookAndFeel() { 
     String[] names = { 
       UIManager.getSystemLookAndFeelClassName(), 
       UIManager.getCrossPlatformLookAndFeelClassName() 
     }; 
     for (String name : names) { 
      try { 
       UIManager.setLookAndFeel(name); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
      // very important to get the window decorations. 
      JFrame.setDefaultLookAndFeelDecorated(true); 
      JFrame f = new JFrame(UIManager.getLookAndFeel().getName()); 
      f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 

      JPanel gui = new JPanel(new BorderLayout()); 
      f.setContentPane(gui); 

      JTree tree = new JTree(); 
      tree.setVisibleRowCount(4); 
      gui.add(tree, BorderLayout.LINE_START); 

      gui.add(new JScrollPane(new JTextArea(3,15))); 

      JToolBar toolbar = new JToolBar(); 
      gui.add(toolbar, BorderLayout.PAGE_START); 
      for (int ii=1; ii<5; ii++) { 
       toolbar.add(new JButton("Button " + ii)); 
       if (ii%2==0) { 
        toolbar.addSeparator(); 
       } 
      } 

      f.pack(); 

      f.setLocationByPlatform(true); 
      f.setVisible(true); 
     } 
    } 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       new FrameCloseButtonsByLookAndFeel(); 
      } 
     }); 
    } 
} 
相关问题