TreeView中TreeItem选择宽度 [英] TreeItem selection width in a TreeView

查看:78
本文介绍了TreeView中TreeItem选择宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaFX 8,目前正在做一些GUI开发.我的TreeView有点问题,需要您的帮助.

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.

您知道在TreeView中是否可以仅选择标签,而不选择TreeCell的整个宽度吗?

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

我的意思是(例如Netbeans):

I mean (Netbeans example) :

而不是:

谢谢.

推荐答案

请尝试在TreeCell中添加标签.
例如:

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);
        }
    }
}

如果使用"TreeView.setCellFactory"方法返回单元格,就可以了.

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

这篇关于TreeView中TreeItem选择宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆