(since this is written on company time, I don't publish the whole thing, but the model for it is trivial)
\npublic class ThreeStateCheckBox extends JCheckBox\n{\n\n static ButtonModel thirdStateModel = new AlwaysPressedSelectedArmedModel();\n\n ThreeStateCheckBox(String text) {\n super(text); \n setModel(new ThreeStateButtonModel());\n }\n\n protected void paintComponent(Graphics g) {\n ThreeStateButtonModel model = (ThreeStateButtonModel)getModel();\n \n if (model.getThirdState() && model.isEnabled()) {\n // in this state, we want the checkbox to be painted selected,\n // pressed an armed. So, we substitute our real model with a\n // fake one that returns selected, pressed and armed no matter\n // what. Then, after the painting is done, we restore the original model.\n \n // this relies on the single-threaded nature of Swing - no other\n // events will be processed while we're painting. We will have\n // to change the code if mouse clicks will start happening in\n // parallel with painting\n\n // we have to access "model" directly, because setModel() causes\n // a reppint, among other things\n\n this.model = thirdStateModel;\n super.paintComponent(g);\n this.model = model;\n\n // back to the originally scheduled programming\n\n } else {\n super.paintComponent(g); \n }\n }\n\n void setThirdState() {\n ((ThreeStateButtonModel)getModel()).setThirdState();\n }\n\n boolean getThirdState() {\n return ((ThreeStateButtonModel)getModel()).getThirdState();\n }\n\n /// The model that cause the checkbox to paint itself in the right\n /// way in the third state\n static public class AlwaysPressedSelectedArmedModel extends DefaultButtonModel {\n public boolean isPressed() {\n return true;\n }\n\n public boolean isArmed() {\n return true;\n }\n \n public boolean isSelected() {\n return true;\n }\n\n }\n\n<model code here>\n\n}\n\n