【问题标题】:Set JLabel icon in Synth xml在 Synth xml 中设置 JLabel 图标
【发布时间】:2011-10-26 23:20:21
【问题描述】:

我正在尝试在合成器 xml 文件中设置 JLabel 的图标,但它不显示。我试图同时设置 defaultIcon 和 icon 属性,但似乎都没有。我应该在这里使用 JLabel 以外的东西吗?这是我的代码:

 <style id="dayBgLabelStyle">
     <imageIcon id="bg" path="images/WG_selectionFields-2.png"/>
     <property key="defaultIcon" value="bg"/>
     <property key="icon" value="bg"/>
 </style>

 <bind style="dayBgLabelStyle" type="name" key="dayBgLabel"/>

JLabel dayBgLabel = new JLabel();
dayBgLabel.setName("dayBgLabel");
dayBgLabel.setIcon(createImageIcon("images/selectionFields-2.png"));

protected static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = testClass.class.getResource(path);
    if (imgURL != null)
        return new ImageIcon(imgURL);
    else
        return null;
}

【问题讨论】:

  • 能否为您创建的合成器样式添加绑定线?

标签: java swing synth


【解决方案1】:

我知道这已经晚了,但也许它可以帮助其他人。

我设法通过使用添加图像

&lt;imagePainter path="images/WG_selectionFields-2.png"" sourceInsets="1 1 5 5" /&gt;

而不是使用 imageIcon。我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    • 2014-01-08
    • 2011-09-05
    相关资源
    最近更新 更多