Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checkbox using Swing  RSS feed

 
sahitya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have few queries regarding Check Box.

1. How to make a checkbox non editable?
2. How to attach an image to the checkbox?

Please help.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see checkBox constructors
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sahitya sahitya:

1. How to make a checkbox non editable?
2. How to attach an image to the checkbox?




Check this out.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setEnabled(false)

JCheckBox(Icon icon);
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setIcon(Icon) should also work.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
setIcon(Icon) should also work.


Actually it doesn't, inasmuch as the icon will replace the default icon, which is the square with the check.

This is a partially implemented UI delegate which paints a custom icon in addition to the default one, in the text area of the JCheckBox.

A fuller implementation would also need to override setPreferredSize and get/set Size, Maximum/Minimum Size .. (maybe get/setBounds, too.. haven't really thought about it).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!