swing: creating "record" and "stop" buttons
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?
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.
You can get icons by name from the L&F, as shown below and in this example.
Icon icon = UIManager.getIcon("OptionPane.errorIcon");
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 using Graphics2D
primitives, as shown here.
精彩评论