【问题标题】:Jcomponent properties with double quote带双引号的 Jcomponent 属性
【发布时间】:2015-06-05 14:34:43
【问题描述】:

我有一个与此代码相关的问题

public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
        String property = propertyChangeEvent.getPropertyName();
        if ("background".equals(property)) {
          button2.setBackground((Color)propertyChangeEvent.getNewValue());

你能解释一下这部分代码,“背景”.equals(property)吗?为什么它使用双引号作为背景?

【问题讨论】:

    标签: java jcomponent swingx


    【解决方案1】:

    "background" 是一个字符串 - 它正在测试property 的值是否等于字符串"background"。

    【讨论】:

    • 这个呢? UIManager.put("Button.background", Color.BLACK); UIManager.put("Button.foreground", Color.RED);v
    • 我根本不知道这个框架,但是看起来它正在为背景和前景设置颜色,只是从变量和方法名称中猜测。
    • 对不起,如果我再问一遍,为什么它使用双引号,“Button.background”?
    • 大概是一个字符串。除此之外,我不能说,您必须检查文档以了解 UIManager 是什么对象。它可能正在做一些事情,比如将Color.BLACK 的值存储在一个名为“Button.background”的元素中,但在不知情的情况下做出假设是危险的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多