Checkboxes and Radio Buttons Together in a JTree
Posted
by
Thunderforge
on Stack Overflow
See other posts from Stack Overflow
or by Thunderforge
Published on 2012-12-07T21:05:39Z
Indexed on
2012/12/07
23:04 UTC
Read the original article
Hit count: 545
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?
© Stack Overflow or respective owner