JavaFX UI Management Architecture (Management + Skin) Using FXML

JavaFX8 has a User Interface Architecture that is used to create custom controls. It is mainly based on:

  • Control
  • Leather.
  • CSS

In addition, there is the basic structure of the FXML project , which is also used to create the GUI. Basically:

  • Control
  • FXML file.
  • CSS

I would like to use FXML with the user interface control panel , so my question is:

Who is the controller for the FXML file? Leather?

I need to do something like this code below:

public class MySkin extends SkinBase<MyControl> {
public GaugeSkin(MyControl control) {
    super(control);
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MyView.fxml"));
    fxmlLoader.setRoot(control);
    fxmlLoader.setController(control);

    try {
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}
+4
1

, Skin, FXML, Skin, , " " ,

Control , , , Skin ( , , ).

, , fxmlloader.setController(control); fxmlloader.setController(this);, Skin , .

, , - FXMLLoader , , Skin, :

public abstract class FXMLSkin<C extends Control> extends SkinBase<C>{

    public FXMLSkin(C control) {
        super(control);
        this.load();
    }

    private void load() {
        FXMLLoader loader = new FXMLLoader(getFXML());
        loader.setController(this);

        try {
            Node root = loader.load();
            this.getChildren().add(root);
        } catch (IOException ex) {
            Logger.getLogger(FXMLSkin.class.getName()).log(Level.SEVERE, null, ex);
        }   
    }

    protected abstract URL getFXML();
}

JavaFX UserControl Github, - FXMLSkinBase . FXML , , FXML . .. FooControlSkin, FXML FooControlSkin.fxml.

, FXMLSkinBase, .

+3

Source: https://habr.com/ru/post/1544502/


All Articles