1 Attachment(s)
How to implement JCheckBox inside JButton?
I was trying some solutions, and every of them failed. Until now, I had thought that anything is possible in Java. One of my solution, that don't makes compilation warrning and runs (but checkbox is missing anyway) is:
Attachment 744
Code :
class myCheckBox extends JCheckBox implements Icon {
int w = 20;
public myCheckBox() {
super();
setSelected(true);
setFocusPainted(false);
setOpaque(false);
setToolTipText(" close route ");
addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) { }
}
});
}
public void paintIcon(Component c, Graphics g, int x, int y) { }
public int getIconWidth() { return w; }
public int getIconHeight() { return w; }
}
then
Code :
myCheckBox CB = new myCheckBox();
button.setIcon(CB);
Any tryings of creating own button class with own content manager fails as well. Any ideas to solve this?
Re: How to implement JCheckBox inside JButton?
Unbelivable easy solution! Thanks.
Code :
JCheckBox jcb = new JCheckBox();
button.add(jcb);
Re: How to implement JCheckBox inside JButton?
Quote:
Originally Posted by
s1w
Unbelivable easy solution! Thanks.
Code :
JCheckBox jcb = new JCheckBox();
button.add(jcb);
Great!!! I have tried it. Cannot believe it is possible:cool:
java memory