Skip to main content

Icon in awt Checkbox

3 replies [Last post]
mkant
Offline
Joined: 2010-02-03
Points: 0

Hello,

I have a question.
Is there a workaround to integrate an icon in an awt checkbox? (analog to JCheckbox)

Thank you very much.

Best regards,

Mathias

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Hinkmond Wong

phonemeadvanced@mobileandembedded.org wrote:
> I have a question.
> Is there a workaround to integrate an icon in an awt checkbox? (analog to JCheckbox)
>

Hi Mathias,

You can try this:

Subclass the AWT Checkbox class and override the paint method to draw
your own icon instead:

public void paint(Graphics g) {
// call super's paint method
super.paint(g);

g.drawImage(...); // use any of the many drawImage variants here !
}

Hinkmonnd

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net

mkant
Offline
Joined: 2010-02-03
Points: 0

public class IconCheckbox extends Checkbox{

Image imageIcon;
String label;

public IconCheckbox (String _path, String _label) {
this.imageIcon = this.getImage(_path);
this.label = _label;
// this.setLabel(_label);
}

public Image getImage(String _path) {
return Toolkit.getDefaultToolkit().getImage(_path);
}

public void paint(Graphics _g) {
_g.drawImage(this.imageIcon, 0, 0, this);
_g.drawString(this.label, 120, 25);
}
}

This works, but there is the clickButton from the Checkbox.
I only want the image and the label.
Do you know how to do that?

Thank you.

Best regards,

Mathias

Hinkmond Wong

phonemeadvanced@mobileandembedded.org wrote:
> public class IconCheckbox extends Checkbox{
>
> Image imageIcon;
> String label;
>
> public IconCheckbox (String _path, String _label) {
> this.imageIcon = this.getImage(_path);
> this.label = _label;
> // this.setLabel(_label);
> }
>
> public Image getImage(String _path) {
> return Toolkit.getDefaultToolkit().getImage(_path);
> }
>
> public void paint(Graphics _g) {
> _g.drawImage(this.imageIcon, 0, 0, this);
> _g.drawString(this.label, 120, 25);
> }
> }
>
>
> This works, but there is the clickButton from the Checkbox.
> I only want the image and the label.
> Do you know how to do that?
>

Try subclassing Button instead of Checkbox.

Hinkmond

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net