Swing Outline with Checkbox in node column

236 views Asked by At

I am creating an JOutline that has rooms, and inside each room has multiple products. You can select an individual product and hit details, but I also need to be able to select check boxes next to multiple products using a checkbox.

I am particularly looking for a way to have the checkbox on the far left of the objects.

Is there any way to do this, or am I better of looking into JXTreeTable?

1

There are 1 answers

4
trashgod On

As discussed here, Outline requires your implementation of the RowModel interface, which should be passed to your OutlineModel constructor.

class MyRowModel implements RowModel {…}
TreeModel myModel = new MyTreeModel(…);
OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(
    myModel, new MyRowModel(), …);
Outline outline = new Outline();
outline.setModel(outlineModel);

In your implementation of RowModel, follow the familiar JTable edit/render scheme for a model value of type Boolean:

  • The getColumnClass() implementation should return Boolean.class for the relevant column.

  • The isCellEditable() implementation should return true for the relevant column.

  • The getColumnClass() implementation should return the value from the given node in myModel.

  • The setValueFor() implementation should update the given node, so the renderer will see the new value when editing concludes.

image