TreeItem selection width in a TreeView

你说的曾经没有我的故事 提交于 2019-12-06 07:42:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!