简体   繁体   English

JCheckbox:从jar添加图标而不是要添加标签的目录?

[英]JCheckbox: add icon from jar not a directory to label?

I know it's possible to use HTML but what if you are loading the icon image from a package instead of a directory? 我知道可以使用HTML,但是如果要从包而不是目录中加载图标图像呢?

How would you go about adding icon to a jcheckbox's label? 您如何将图标添加到jcheckbox的标签?

http://www.exampledepot.com/egs/javax.swing/checkbox_AddIcon.html http://www.exampledepot.com/egs/javax.swing/checkbox_AddIcon.html

IconString添加到JLabel ,然后设置JLabel#setLabelFor(myJCheckBox)

I show various ways in my answer to "Loading images from jars for Swing HTML". 我对“从jars中为Swing HTML加载图像”的回答中展示了多种方式。 But using an explicit URL (obtained from Class.getResource(String) ) should work just fine as the src attribute of the img element. 但是使用显式URL(从Class.getResource(String) )应该可以作为img元素的src属性正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM