JavaFX 2:如何以编程方式聚焦表行? [英] JavaFX 2: How to focus a table row programmatically?

查看:186
本文介绍了JavaFX 2:如何以编程方式聚焦表行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过编程方式选择/集中一行 TableView



我可以选择一行,但它不会被呈现为重点(未突出显示)。我已经尝试了以下代码的许多组合,但似乎没有工作。

  table.getSelectionModel()。select(0); 
table.focusModelProperty()。get()。focus(new TablePosition(table,0,column));
table.requestFocus();

是否可以以编程方式高亮显示一行?

我正在使用JavaFX 2.2.21试试把你的请求放在表中,然后把整个东西 runLater

  Platform.runLater(new Runnable()
$ b $覆盖
public void run()
{
table.requestFocus();
table.getSelectionModel()。select(0);
table.getFocusModel()。focus(0);
}
});


I am trying to select/focus a row of a TableView programmatically.

I can select a row, but it is not getting rendered as focused (not highlighted). I have tried many combinations of the code below, but nothing seems to work.

table.getSelectionModel().select(0);
table.focusModelProperty().get().focus(new TablePosition(table, 0, column));
table.requestFocus();

Is it possible to highlight a row programmatically?

I am using JavaFX 2.2.21

解决方案

Try putting your request for table focus first and then wrapping the whole thing in a runLater.

Platform.runLater(new Runnable()
{
    @Override
    public void run()
    {
        table.requestFocus();
        table.getSelectionModel().select(0);
        table.getFocusModel().focus(0);
    }
});

这篇关于JavaFX 2:如何以编程方式聚焦表行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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