再会
我有一个基本工具栏,我在其中添加了 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);