简体   繁体   English

如何根据按下的按钮实例化不同大小的图标java

[英]how to instantiate different size icons based on the button pressed java

How can I change the size of icons that are instantiated based on a button pressed in a method.如何更改基于方法中按下的按钮实例化的图标的大小。

so for instance this is what the buttons are instantiated as所以例如这就是按钮被实例化的内容

private ExitProgramAction exitProgramAction = new ExitProgramAction("Quit",
      Resources.getIcon("exit16"), "Quit HEAT", new Integer(KeyEvent.VK_Q),
      KeyStroke.getKeyStroke(KeyEvent.VK_Q, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

but I am trying to change the getIcon() via the below method (which i created button for) when clicked.但我正在尝试通过以下方法(我为其创建按钮)在单击时更改 getIcon()。

protected class ZoomButtonAction extends AbstractAction {
    public ZoomButtonAction(String text, String desc)
    {
        super(text);
        putValue(SHORT_DESCRIPTION, desc);
    }

    public void actionPerformed(ActionEvent e){


    }
}

You can resize icons with the code below anytime you want.您可以随时使用以下代码调整图标大小。

protected class ZoomButtonAction extends AbstractAction {
    public ZoomButtonAction(String text, String desc)
    {
        super(text);
        putValue(SHORT_DESCRIPTION, desc);
    }

    public void actionPerformed(ActionEvent e){

        ImageIcon icon = (ImageIcon)getValue(Action.SMALL_ICON);
        Image newImage = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
        putValue(Action.SMALL_ICON, new ImageIcon(newImage));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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