-1

I have a javaFX application with fxml file. I don't understand how I can adapt to other screens. That is, I have 1920x1080 and the application is in full screen, and at 1366x768 it cuts it almost 2 times.

My startup class:

public class FrameStart extends Application {

    static Logger LOGGER;
    static {
        try(FileInputStream ins = new FileInputStream("src/main/resources/log.config")) {
            LogManager.getLogManager().readConfiguration(ins);
            LOGGER = Logger.getLogger(FrameStart .class.getName());
        } catch (IOException e) {
            LOGGER.log(Level.WARNING,"Error ", e);
        }
    }
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage)  {
        try {
            FXMLLoader loader = new FXMLLoader();
            URL xmlUrl = getClass().getResource("/Scene.fxml");
            loader.setLocation(xmlUrl);
            Parent root = loader.load();
            stage.setTitle("App");
            stage.getIcons().add(new Image(FrameStart .class.getClassLoader().getResourceAsStream("logo.png")));
            stage.setScene(new Scene(root));
            stage.show();
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE,"Error", e);
        }
    }
}

I don't really understand how to adapt
Vanish
  • 57
  • 6
  • 1
    Have you tried https://stackoverflow.com/a/31427041/2423906? – SedJ601 Jun 22 '23 at 15:55
  • An animation example cited [here](https://stackoverflow.com/a/31761362/230513), illustrates how "to scale a background image while retaining its aspect ratio." – trashgod Jun 22 '23 at 17:11

1 Answers1

-4

One way of doing this:

Create a design which is responsive.

I recommend you to use Scenebuilder for this. Use layoutpanes (e.g. BorderPane) as wrapper. Create nested layoutpanes in another layoutpanes. Use preferred sizes with the value "computed size" in elements that shall be responsive. Every element you do not define its sizes will not be responsive.

You need to take a look the the properties of the elements. There are things like wrapping (e.g. Text), alignmemt, etc.

David Weber
  • 173
  • 9