3

I'm using JavaFX 8 and I'm currently doing some GUI developments. I have a little problem with my TreeView and I need your help.

Do you know if it is possible, in a TreeView, to select just the label and not the whole width of the TreeCell ?

I mean (Netbeans example) :

Good TreeView selection

Instead of :

Bad TreeView selection

Thank you in advance.

Jbprod
  • 209
  • 2
  • 8
  • the "look" can be achieved via styling (see http://stackoverflow.com/q/28113294/203657 or more precisely: the accepted answer) - but that'll still leaves the "feel" open - needs some work to ignore mouse-event outside the label – kleopatra Jan 26 '15 at 14:48

1 Answers1

1

Please try adding a Label inside TreeCell.
for example:

private static class YourItemCell extends TreeCell<YourItem>
{
    Label label;

    public YourItemCell()
    {
        label = new Label();
    }

    @Override
    protected void updateItem(YourItem item, boolean empty)
    {
        super.updateItem(item, empty);
        if (!empty && item != null)
        {
            label.setText(item.getText());
            setGraphic(label);
        }
    }
}

If you return the cell using the "TreeView.setCellFactory" method, it's okay.

guest
  • 11
  • 1