【发布时间】:2015-12-17 08:45:43
【问题描述】:
我正在尝试将 FXML 加载到 TitledPane 中。但它看起来很模糊。 不知道是什么原因。
我的代码包括 2 个文件,如下所示:
MainTitlePane.java
public class MainTitlePane extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws IOException {
stage.setTitle("TitledPane");
Scene scene = new Scene(new Group(), 500, 800);
scene.setFill(Color.GHOSTWHITE);
//Load AnchorPane from FXML file
FXMLLoader loader1 = new FXMLLoader(getClass().getResource("ChildPane.fxml"));
AnchorPane childPane = (AnchorPane) loader1.load();
//Add pane to TitledPane
TitledPane tps1 = new TitledPane("First",childPane);
Accordion acc = new Accordion (tps1);
acc.setExpandedPane(tps1);
//Add button outside of TitledPane
Button btnTest = new Button("Button Direct");
btnTest.setLayoutX(250.0);
btnTest.setLayoutY(250.0);
Group root = (Group)scene.getRoot();
root.getChildren().addAll(acc, btnTest);
stage.setScene(scene);
stage.show();
}
}
和 ChildPane.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ScrollPane layoutX="673.0" prefHeight="380.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="300.0" prefWidth="189.0">
<children>
<Label layoutX="31.0" layoutY="22.0" text="Hello world" />
<Button layoutX="49.0" layoutY="159.0" mnemonicParsing="false" text="Submit" />
</children>
</AnchorPane>
</content>
</ScrollPane>
</children>
</AnchorPane>
当我运行我的代码时,应用程序如下图所示:
如何解决我的问题?
谢谢!
【问题讨论】: