Checkboxes and Radio Buttons Together in a JTree
- by Thunderforge
I'd like to create a JTree that more or less has the following structure (with a hidden root node)
[No Option] Main Dish
[Radio Button] Steak
[Radio Button] Fish
[Radio Button] Filet Mignon
[Checkbox] Side Dish
[Checkbox] Mashed Potatoes
[Checkbox] Green Beans
[Checkbox] Mixed Vegetables
[Checkbox] Dessert
[Radio Button] Ice Cream
[Radio Button] Pudding
[Radio Button] Cake
Basically, at least one main dish (but no more than one) can be chosen, any number of side dishes can be chosen (or none, if the "Side Dish" checkbox is unchecked), and only one dessert can be chosen (or none, if the "Dessert" checkbox is unchecked).
This article describes how to create a tree that uses JCheckboxes (as I'd like to use for the Side Dish and Dessert sections) by creating a custom Renderer and page 3 of the same article describes how to use Radio buttons (as I'd like to use for the Main Course) section. But it doesn't describe how to mix them up within the same JTree.
Is it possible to create a structure like this? And if so, how?