繁体   English   中英

调整ToolBar图标的大小

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM