Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to implement a three-state checkbox?

Status
Not open for further replies.

Dhafir

Programmer
Sep 22, 2002
28
0
0
NZ
Hi all,
The required third state is "half checked" or grey coloured. An example is when you look at the properties of a folder in File Explorer where part of the files in the folder are read only. In this case the "Read Only" check box will look grey.

Can someone please point me to an implementation ?

Regards
 
Hi Dhafir,
Are you talking about when the checkbox is disabled?
MarsChelios
 

No.. it will look as if it is disabled but it is not. Otherwise you can not click it again.
 
So you are asking for the check box to be
a) normal mode (eg chackable and in full colour)
b) disabled (not checkable and greyed out)
c) third mode (checkable, but greyed out)

yes?

If that is the case could you not perhaps just manually change the text label of the checkbox to appear gray?

I however cannot remember if the actual checkbox graphic changes colour or not in disabled mode. If it does you will have to overwrite the paint() method and look after all the drawing of the check box yourself. This is quite possible, just a bit fiddly.

Or (something else just occured to me) since it is possible to have a checkbox with custom graphics (eg a lightglobe picture that is off when unchecked and on when checked - see the SwingSet.jar demo), could you not provide your own graphics of the check box? An unchecked box graphic, a checked box graphic, and a checked but grayed out box graphic, and switch between them at will (there will be a method called something like setIcon/setGraphic that should let you do this.)


Is that what you are after? ----------------------------------------
There are no onions, only magic
----------------------------------------
 
Hi jfryer,
I was after the last bit only.

I have just implemented this class, a Tri-State Checkbox. It is actuall a JLable class with a state and mouse listener. It worked perfectly. It has three icons (checked, unchecked and half-checked or greyed).

If you have a 20 files in a folder, some of them ( not all ) are read only and the rest are writable, then if you right click on the folder and select properties, you will see the "Read Only" check box is ticked but greyed out to indicate that only some files are read only. If you click on the check box it will be unchecked, if click again, it will check it, if you click for the third time it will ticked but greyed out again - this is called Tri-State check box.

Thanks for every one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top