Where are these error and warning icons as a java resource?

点点圈 提交于 2019-11-27 04:33:22

问题


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:

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?


回答1:


We use them too via:

UIManager.getIcon("OptionPane.errorIcon")

UIManager.getIcon("OptionPane.warningIcon")



回答2:


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



来源:https://stackoverflow.com/questions/1196797/where-are-these-error-and-warning-icons-as-a-java-resource

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!