2012-01-24 102 views
0

美好的一天調整工具欄圖標大小

我有一個基本的工具欄,我添加了ImageIcon按鈕。但圖像大小不同。 我將如何去調整圖標的大小,使它們都是相同的大小。

super("ToolBar"); 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    //creating the icons for the toolbar 
    ImageIcon savePic = new ImageIcon("c:/Exercises/unitTwo/Chapter Three/Images/save.png"); 
    ImageIcon openFilePic = new ImageIcon("c:/Exercises/unitTwo/Chapter Three/Images/open.png"); 
    ImageIcon printPic = new ImageIcon("c:/Exercises/unitTwo/Chapter Three/Images/print.png"); 



    //creating buttons with initial text and icons. I.o.w. the buttons for the toolbar are created 

    JButton save = new JButton("Save", savePic); 
    JButton open = new JButton("Open", openFilePic); 
    JButton print = new JButton("Print", printPic); 


    JToolBar bar = new JToolBar(); 
    bar.add(save); 
    bar.add(open); 

    bar.add(new JToolBar.Separator()); 
    bar.add(print); 

    JTextArea text = new JTextArea(10, 40); 


    add(BorderLayout.NORTH, bar); 
    add(BorderLayout.CENTER, text); 

    pack(); 
    setVisible(true); 
+0

使用Gimp(http://www.gimp.org/)等圖像編輯器編輯程序外部的圖像。 –

+0

鑑於存在可用的圖標庫(每個提供相同寬度和高度的圖標),例如保存,打開和打印等,我傾向於使用其中一組,而不是嘗試使用繪圖程序或在運行時修改某些圖像-時間。調整這些小圖像的大小通常會導致可怕的圖標。 –

回答

2

火烈鳥組件套件支持可調整大小的圖標,其中一個支持類是ImageWrapperResizableIcon。您可以嘗試查看源代碼,以瞭解如何實現自動調整圖標大小,而無需手動執行此操作。

或者,您可以自己創建一個圖像大小調整後的版本,並使用該大小調整後的版本創建ImageIcon