我正在尝试为ControlsFX的Borders API创建一个包装器,它将与FXML一起使用。当我运行我的应用程序时,我看不到任何内容。当我将TitledBorder
更改为其他内容时,就像Label
一样,它按预期工作。
TitledBorder类:
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;
}
}
主要fxml测试:
<?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>
主要课程:
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();
}
}