挥杆:创造“纪录”和“停止”按钮
我看到有一个 JButton
构造函数 以 Icon
作为参数...但是如何从位图文件中获取 Icon
?
另外,默认外观中是否有“记录”和“停止”图标?还是我必须自己提供?
I see that there is a JButton
constructor which takes an Icon
as a parameter... but how do I get an Icon
from a bitmap file?
Also, are there "record" and "stop" Icon
s available from the default look and feel? or do I have to provide them myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从 URL 创建 ImageIcon等(包括文件名或字节数组)。
您还可以将任何图像传递到构造函数中,这意味着您可以充分利用 ImageIO 实用程序类。
You can create an ImageIcon from a URL, among other things (including a filename or a byte array).
You can also pass any Image into the constructor, meaning you can take full advantage of the ImageIO utility class.
您可以从 L&F 中按名称获取图标,如下所示以及此示例中。
您可以使用 Rob Camick 方便的 UIManager 默认值。
附录:另一种方法是实现
Icon
接口并使用Graphics2D
原语绘制图标,如图You can get icons by name from the L&F, as shown below and in this example.
You can see what's available using Rob Camick's handy UIManager Defaults.
Addendum: Another approach is to implement the
Icon
interface and draw the icon usingGraphics2D
primitives, as shown here.