Issue
I am trying to loading a FXML into TitledPane. but it look like very blurred. I dont know the reason.
My code include 2 files like below:
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();
}
}
and 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>
When i run my code, the app look like the image below:
How I can fix my problem?
Thanks!
Solution
I have found the reason, i am using ScrollPane in ChildPane.fxml, the scroll bar will zoom the screen, i think that is the reason. It worked if i remove ScrollPane . Thanks
Answered By - MartinJoo
Answer Checked By - Candace Johnson (JavaFixing Volunteer)