TreeItem selection width in a TreeView

405 views Asked by At

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.

1

There are 1 answers

0
guest On

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.