问题
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) :
Instead of :
Thank you in advance.
回答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.
来源:https://stackoverflow.com/questions/23792004/treeitem-selection-width-in-a-treeview