这些错误和警告图标作为java资源在哪里? [英] Where are these error and warning icons as a java resource?

查看:173
本文介绍了这些错误和警告图标作为java资源在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();
    }
}

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

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?

推荐答案

我们也通过以下方式使用它们:

We use them too via:

UIManager.getIcon("OptionPane.errorIcon")

UIManager.getIcon("OptionPane.warningIcon")

这篇关于这些错误和警告图标作为java资源在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆