2

I am trying to create a wrapper for ControlsFX's Borders API that will work with FXML. When I run my application, I do not see any content. When I changed the TitledBorder to something else, like a Label, it worked as intended.

TitledBorder class:

package com.neonorb.commons.ui.gui.javafx;

import javafx.beans.NamedArg;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import org.controlsfx.tools.Borders;

/**
 * Created by chris on 8/21/15.
 */

public class TitledBorder extends StackPane {
    private StackPane contentStackPane = new StackPane();
    private ObservableList<Node> children = contentStackPane.getChildren();

    public TitledBorder(@NamedArg("text") String text) {
        super.getChildren().add(Borders.wrap(contentStackPane).lineBorder().color(Color.BLACK).title(text).buildAll());
    }

    public ObservableList<Node> getChildren() {
        return children;
    }
}

Main fxml test:

<?import javafx.scene.layout.BorderPane?>
<?import com.neonorb.commons.ui.gui.javafx.TitledBorder?>
<?import javafx.scene.control.Label?>
<BorderPane xmlns:fx="http://javafx.com/fxml">
    <center>
        <TitledBorder text="hi">
            <children>
                <Label text="hello"/>
            </children>
        </TitledBorder>
    </center>
</BorderPane>

Main class:

import com.neonorb.commons.Commons;
import com.neonorb.commons.MainClass;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 * Created by chris on 7/7/15.
 */

@MainClass
public class Main extends Application {
    public static void main(String[] args) {
        launch();
    }

    @Override
    public void start(Stage stage) throws Exception {
        Commons.init("");
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Main.fxml"));
        Parent parent = fxmlLoader.load();
        stage.setScene(new Scene(parent));
        stage.sizeToScene();
        stage.show();
    }
}
Chris Smith
  • 2,928
  • 4
  • 27
  • 59

0 Answers0