dynamic checkbox icon
来源:互联网 发布:国内大数据龙头企业 编辑:程序博客网 时间:2024/05/20 10:22
A TRICKY FOR DYNAMIC CHECKBOX ICON
public static class CheckBoxIcon implements Icon {
private ImageIcon checkedIcon = (ImageIcon)ControlUtil.createIcon("Bold");
private ImageIcon checkedIcon = (ImageIcon)ControlUtil.createIcon("Bold");
private ImageIcon uncheckedIcon = (ImageIcon)ControlUtil.createIcon("Underline");
public void paintIcon(Component component, Graphics g, int x, int y) {
AbstractButton abstractButton = (AbstractButton) component;
ButtonModel buttonModel = abstractButton.getModel();
g.translate(x, y);
ImageIcon imageIcon = buttonModel.isSelected() ? checkedIcon
: uncheckedIcon;
Image image = imageIcon.getImage();
g.drawImage(image, 0, 0, component);
g.translate(-x, -y);
}
AbstractButton abstractButton = (AbstractButton) component;
ButtonModel buttonModel = abstractButton.getModel();
g.translate(x, y);
ImageIcon imageIcon = buttonModel.isSelected() ? checkedIcon
: uncheckedIcon;
Image image = imageIcon.getImage();
g.drawImage(image, 0, 0, component);
g.translate(-x, -y);
}
public int getIconWidth() {
return 20;
}
return 20;
}
public int getIconHeight() {
return 20;
}
}
return 20;
}
}
THIS IS THE OFFICAL WAY
public class JCheckBoxCustomIcon extends JFrame {
public JCheckBoxCustomIcon() throws HeadlessException {
initialize();
}
private void initialize() {
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.LEFT));
// Creating checkbox with text label
JCheckBox checkBox = new JCheckBox("Check me!");
checkBox.setSelected(true);
// Set default icon for checkbox
checkBox.setIcon(new ImageIcon("icon.png"));
// Set selected icon when checkbox state is selected
checkBox.setSelectedIcon(new ImageIcon("selectedIcon.png"));
// Set disabled icon for checkbox
checkBox.setDisabledIcon(new ImageIcon("disabledIcon.png"));
// Set disabled-selected icon for checkbox
checkBox.setDisabledSelectedIcon(new ImageIcon("disabledSelectedIcon.png"));
// Set checkbox icon when checkbox is pressed
checkBox.setPressedIcon(new ImageIcon("pressedIcon.png"));
// Set icon when a mouse is over the checkbox
checkBox.setRolloverIcon(new ImageIcon("rolloverIcon.png"));
// Set icon when a mouse is over a selected checkbox
checkBox.setRolloverSelectedIcon(new ImageIcon("rolloverSelectedIcon.png"));
getContentPane().add(checkBox);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new JCheckBoxCustomIcon().setVisible(true);
}
});
}
public JCheckBoxCustomIcon() throws HeadlessException {
initialize();
}
private void initialize() {
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.LEFT));
// Creating checkbox with text label
JCheckBox checkBox = new JCheckBox("Check me!");
checkBox.setSelected(true);
// Set default icon for checkbox
checkBox.setIcon(new ImageIcon("icon.png"));
// Set selected icon when checkbox state is selected
checkBox.setSelectedIcon(new ImageIcon("selectedIcon.png"));
// Set disabled icon for checkbox
checkBox.setDisabledIcon(new ImageIcon("disabledIcon.png"));
// Set disabled-selected icon for checkbox
checkBox.setDisabledSelectedIcon(new ImageIcon("disabledSelectedIcon.png"));
// Set checkbox icon when checkbox is pressed
checkBox.setPressedIcon(new ImageIcon("pressedIcon.png"));
// Set icon when a mouse is over the checkbox
checkBox.setRolloverIcon(new ImageIcon("rolloverIcon.png"));
// Set icon when a mouse is over a selected checkbox
checkBox.setRolloverSelectedIcon(new ImageIcon("rolloverSelectedIcon.png"));
getContentPane().add(checkBox);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new JCheckBoxCustomIcon().setVisible(true);
}
});
}
- dynamic checkbox icon
- dynamic cleandar icon
- [WPF] How to dynamic bind Menuitem's Header and Icon
- WPF 4 动态覆盖图标(Dynamic Overlay Icon)
- WPF 4 动态覆盖图标(Dynamic Overlay Icon)
- 微信小程序icon,text,progress,button,checkbox,form
- checkbox android:button="@null" 默认checkbox icon仍占位问题
- icon
- icon
- icon
- ICON
- ICON
- icon
- icon
- Icon
- dynamic
- @dynamic
- Dynamic
- Ant
- 【原】用于生成给定带权重的节点的霍夫曼编码
- eclipse汉化包如何使用(转)
- rose2003下载安装破解汉化
- unix域套接口示例程序
- dynamic checkbox icon
- window xp 安装 IIS
- asp.net 多线程
- Blackberry textField align to right
- json与Bean对象互相转换
- Android无法访问本地服务器(localhost)的解决方案
- 中州黑客2010
- JQuery上传插件Uploadify使用详解
- 恋人的保质期