find JavaFX Tab - Java JavaFX

Java examples for JavaFX:TabPane

Description

find JavaFX Tab

Demo Code

/**// w w w . j a  v a 2 s .co m
 * Author: obullxl@gmail.com
 * Copyright (c) 2004-2013 All Rights Reserved.
 */
//package com.java2s;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;

public class Main {

    public static Tab findTab(TabPane tabpane, Object userData) {
        if (userData == null) {
            return null;
        }

        if (tabpane == null) {
            return null;
        }

        for (Tab tab : tabpane.getTabs()) {
            Object tabUserData = findTabUserData(tab);
            if (tabUserData == null) {
                return null;
            }

            if (userData.equals(tabUserData)) {

                return tab;
            }
        }


        return null;
    }

    @SuppressWarnings("unchecked")
    public static <T> T findTabUserData(Tab tab) {
        if (tab == null) {
            return null;
        }

        Object object = tab.getUserData();
        if (object == null) {
            return null;
        }

        return (T) object;
    }
}

Related Tutorials