简体   繁体   中英

JavaFX Scene Builder custom tab

I have created own custom control for JavaFX. It is working well when I have add it manually into FXML file. And it is "invisible" for Java Scene Builder when I tried to import it. So, I have next code (extremely simplified version): MyTab.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.* ?>
<?import tafm.javafx.controls.MyTab?>


<fx:root type="javafx.scene.control.Tab" xmlns:fx="http://javafx.com/fxml">
</fx:root>

MyTab.java

package tafm.javafx.controls;

import javafx.fxml.FXMLLoader;
import javafx.scene.control.Tab;

import java.io.IOException;

public class MyTab extends Tab {

    public MyTab() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MyTab.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        fxmlLoader.setClassLoader(getClass().getClassLoader());
        try {
            fxmlLoader.load();            
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }
}

I have build an jar file with this control and tried to import it into JavaFX Scene Builder 2.0. It is imported just with one error "Not a node: tafm.javafx.controls.MyTab.class" and there is no MyTab control available.

Then I change this class (together with fxml) as:

public class MyTab extends HBox

(just for testing purposes). It is successfully loaded into SB! So, as I understand, it is impossible to create an own "Tab". Is it true? Sure, I can manually edit the fxml files, but I would like to do it in SB. Does some workaround exists?

The Tab in JavaFX is not inherited from the Node . It is also clear from the message you get.

All custom controls have to be part of the scene graph ie based on the Node . It is preferable that all custom controls inherit from Control , which will simplify and standardize their development.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM