49
I have a JavaFX application which has only one FXML file. I have AnchorPane with Image ( 1920×1080)](https://i.sstatic.net/19qGty53.png). When i run, i want to see full image. but the program automatically scale up my anchorpane, it happened with my StackPane too.
My Code
FXML
<AnchorPane prefHeight="1080.0" prefWidth="1920.0" stylesheets="@../CSS/Account/RecoverAccount.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.group3.cinemabooking.Client.ClientViewController">
<ImageView fitHeight="1080.0" fitWidth="1920.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../../../../Images/universal.jpg" />
</ImageView>
</AnchorPane>
App.java
public class App extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Client/ClientView.fxml"));
scene = new Scene(fxmlLoader.load(), 1920, 1080);
stage.setScene(scene);
stage.setTitle("Login");
stage.show();
}
private static Parent loadFXML(String url) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(url + ".fxml"));
return fxmlLoader.load();
}
public static void setRoot(String fxml, String title) throws Exception {
scene.setRoot(loadFXML(fxml));
Stage primaryStage = (Stage) scene.getWindow();
primaryStage.setTitle(title);
}
public static void main(String[] args) {
launch();
}
}
i tried to fix that but cant. what i want to see is when i run, JavaFX will not scale up my file.
New contributor
kar1a is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.