[英]Resizing the ToolBar icons
美好的一天
我有一個基本的工具欄,我添加了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);
flamingo組件套件支持可調整大小的圖標,其中一個支持類是ImageWrapperResizableIcon 。 您可能會嘗試查看源代碼,以了解如何實現自動調整圖標大小而無需手動執行此操作。
或者,只需自己創建一個調整大小的圖像版本,然后使用該調整大小的版本創建ImageIcon
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.