将侦听器添加到使用TabPaneBuilder创建的TabPane吗? [英] Adding a listener to a TabPane created with TabPaneBuilder?

查看:60
本文介绍了将侦听器添加到使用TabPaneBuilder创建的TabPane吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

TabPaneBuilder.create()
    .tabs(
        TabBuilder.create()
            .text("Main")
            .closable(false)
            .build(),
        TabBuilder.create()
            .text("Preview")
            .content(createPreviewSplitMenu())
            .closable(false)
            .build()
        )
   .build()

是否可以在此处添加侦听器,以便在选择预览"选项卡时完成某些操作?如果是这样,我似乎找不到它,并且已经查看了API.

Is it possible to add a listener here so that something is done when the tab "preview" is selected? If so I can't seem to find it and I have looked at the API.

我一般不问怎么做,只是在使用TabPaneBuilder时.

I'm not asking how to do it in general, just when using TabPaneBuilder.

谢谢.

如果我要问的是不可能的,我还想用最简单的常规方法来做.

would also like the simplest regular way to do it if what I am asking is not possible.

Edit2:我想做的是选择预览"标签后重新绘制它的内容.

what I'd like to do is have the content of "Preview" tab redrawn when it is selected.

推荐答案

您需要将侦听器添加到TabBuilder!

You need to add the listener to the TabBuilder!

(需要先给它起个名字,所以以后可以参考它:)

(Need to give it a name first, so you can reference it later:)

TabPaneBuilder.create()
.tabs(
    TabBuilder.create()
        .text("Main")
        .closable(false)
        .build(),

//New code coming through

    previewTab = TabBuilder.create()
        .text("Preview")
        .content(createPreviewSplitMenu())
        .closable(false)

        .onSelectionChanged(new EventHandler<Event>() {
        public void handle(Event evt) {
          if (previewTab.isSelected()) {
            //code to update the tab
          }
        }
      })

      .build()
    )
.build()

这篇关于将侦听器添加到使用TabPaneBuilder创建的TabPane吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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