2012-08-10 325 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(); 
      } 
     }); 
    } 
} 
相關問題