这些错误和警告图标作为java资源在哪里?

时间:2022-08-15 12:39:11

I've got a custom tree cell renderer that I'm using to render custom icons a JTree, and I really like the warning icon and the error icon that JOptionPane displays for both warning messages and error messages respectively. Obviously I can use the following code to get the icons for my own use, but this is way heavy handed and requires me to instantiate dialogs that I'm never going to use:

我有一个自定义树单元格渲染器,我用它来渲染自定义图标JTree,我真的很喜欢警告图标和JOptionPane分别为警告消息和错误消息显示的错误图标。显然,我可以使用下面的代码来获取我自己使用的图标,但这很重要,需要我实例化我永远不会使用的对话框:

public class ValidationCellRenderer extends DefaultTreeCellRenderer {
    private Icon warnIcon;
    private Icon errorIcon;

    public ValidationCellRenderer() {
        JOptionPane optionPane = new JOptionPane(new Object(), 
            JOptionPane.WARNING_MESSAGE);
        warnIcon = optionPane.getIcon();
        optionPane = new JOptionPane(new Object(), 
            JOptionPane.ERROR_MESSAGE);
        errorIcon = optionPane.getIcon();
    }
}

There's got to be a better way to get these icons as a resource, but I'm not finding an easy way to do this from the Java API. Anyone have any suggestions?

必须有更好的方法将这些图标作为资源,但我没有找到一种简单的方法来从Java API中执行此操作。有人有什么建议吗?

2 个解决方案

#1


35  

We use them too via:

我们也使用它们:

UIManager.getIcon("OptionPane.errorIcon")

UIManager.getIcon("OptionPane.warningIcon")

#2


7  

And if you want to know about all the icons and their names you can check out: UIManager Defaults

如果您想了解所有图标及其名称,可以查看:UIManager Defaults

#1


35  

We use them too via:

我们也使用它们:

UIManager.getIcon("OptionPane.errorIcon")

UIManager.getIcon("OptionPane.warningIcon")

#2


7  

And if you want to know about all the icons and their names you can check out: UIManager Defaults

如果您想了解所有图标及其名称,可以查看:UIManager Defaults