Как создать адаптивность для приложения на JavaFX?
Всем доброго утра, дня или вечера. Такая проблема, написано приложение на Java 18 с JavaFx+SceneBuilder. При переходе в FullScreen размер не адаптируется под экран.
FXML File:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.paint.Color?>
<?import javafx.scene.paint.LinearGradient?>
<?import javafx.scene.paint.Stop?>
<?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="882.0" prefWidth="1267.0" style="-fx-background-color: pink;" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.dasha.HelloController">
<children>
<AnchorPane layoutX="606.0" layoutY="-4.0" prefHeight="888.0" prefWidth="661.0" style="-fx-background-color: linear-gradient(to left, #da48da, pink);">
<cursor>
<Cursor fx:constant="DEFAULT" />
</cursor>
<children>
<Circle layoutX="497.0" layoutY="799.0" radius="22.0" stroke="BLACK" strokeType="INSIDE">
<fill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color red="0.5336166620254517" green="0.1405068188905716" blue="0.7157894968986511" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="1.0" green="1.0" blue="1.0" />
</color>
</Stop>
</stops>
</LinearGradient>
</fill>
</Circle>
<Circle layoutX="495.0" layoutY="721.0" radius="22.0" stroke="BLACK" strokeType="INSIDE">
<fill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color red="0.5336166620254517" green="0.1405068188905716" blue="0.7157894968986511" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="1.0" green="1.0" blue="1.0" />
</color>
</Stop>
</stops>
</LinearGradient>
</fill>
</Circle>
<Circle layoutX="497.0" layoutY="287.0" radius="22.0" stroke="BLACK" strokeType="INSIDE">
<fill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color red="0.5336166620254517" green="0.1405068188905716" blue="0.7157894968986511" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="1.0" green="1.0" blue="1.0" />
</color>
</Stop>
</stops>
</LinearGradient>
</fill>
</Circle>
<Circle layoutX="491.0" layoutY="84.0" radius="22.0" stroke="BLACK" strokeType="INSIDE">
<fill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color red="0.5336166620254517" green="0.1405068188905716" blue="0.7157894968986511" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="1.0" green="1.0" blue="1.0" />
</color>
</Stop>
</stops>
</LinearGradient>
</fill>
</Circle>
<Text fill="#dbc9e7" layoutX="367.0" layoutY="51.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Индекс Тона" textAlignment="CENTER" wrappingWidth="246.47866821289062">
<font>
<Font name="Microsoft Sans Serif" size="40.0" />
</font>
</Text>
<Text fx:id="NumberOfTon" fill="WHITE" layoutX="473.0" layoutY="90.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="35.999926757812375">
<font>
<Font name="Arial Bold Italic" size="17.0" />
</font>
</Text>
<TextArea fx:id="TextOfBolton" layoutX="325.0" layoutY="309.0" prefHeight="74.0" prefWidth="331.0" />
<TextField fx:id="PonVivodDown2" layoutX="546.0" layoutY="785.0" prefHeight="26.0" prefWidth="110.0" />
<Text fx:id="PonNormaNiz" fill="WHITE" layoutX="475.0" layoutY="804.0" strokeType="OUTSIDE" strokeWidth="0.0">
<font>
<Font name="Arial Bold Italic" size="17.0" />
</font>
</Text>
<TextField fx:id="PonVivodUp2" layoutX="343.0" layoutY="786.0" prefHeight="26.0" prefWidth="110.0" />
<Text layoutX="334.0" layoutY="776.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Верхняя челюсть (2)">
<font>
<Font name="Bauhaus 93" size="15.0" />
</font>
</Text>
<Text layoutX="519.0" layoutY="775.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Нижняя челюсть (4)">
<font>
<Font name="Bauhaus 93" size="15.0" />
</font>
</Text>
<TextField fx:id="PonVivodDown1" layoutX="546.0" layoutY="707.0" prefHeight="26.0" prefWidth="110.0" />
<Text layoutX="519.0" layoutY="699.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Нижняя челюсть (3)">
<font>
<Font name="Bauhaus 93" size="15.0" />
</font>
</Text>
<TextField fx:id="PonVivodUp1" layoutX="348.0" layoutY="707.0" prefHeight="26.0" prefWidth="110.0" />
<Text layoutX="331.0" layoutY="700.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Верхняя челюсть (1)">
<font>
<Font name="Bauhaus 93" size="15.0" />
</font>
</Text>
<Text fx:id="PonNormaUp" fill="WHITE" layoutX="473.0" layoutY="726.0" strokeType="OUTSIDE" strokeWidth="0.0">
<font>
<Font name="Arial Bold Italic" size="17.0" />
</font>
</Text>
<TextField fx:id="KorkhauzVivodDown" layoutX="317.0" layoutY="587.0" prefHeight="28.0" prefWidth="338.0" />
<Text layoutX="433.0" layoutY="583.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Нижняя челюсть">
<font>
<Font name="Bauhaus 93" size="16.0" />
</font>
</Text>
<TextField fx:id="KorkhauzVivodUp" layoutX="317.0" layoutY="532.0" prefHeight="28.0" prefWidth="338.0" />
<Text layoutX="432.0" layoutY="522.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Верхняя челюсть">
<font>
<Font name="Bauhaus 93" size="16.0" />
</font>
</Text>
<TextField fx:id="KorkHauzDown" layoutX="560.0" layoutY="471.0" prefHeight="16.0" prefWidth="72.0" />
<TextField fx:id="KorkHauzUp" layoutX="332.0" layoutY="471.0" prefHeight="16.0" prefWidth="72.0" />
<Text layoutX="337.0" layoutY="467.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Верхняя">
<font>
<Font name="Bauhaus 93" size="16.0" />
</font>
</Text>
<Text layoutX="567.0" layoutY="467.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Нижняя">
<font>
<Font name="Bauhaus 93" size="16.0" />
</font>
</Text>
<Text fx:id="NumberOfBolton" fill="WHITE" layoutX="479.0" layoutY="292.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="35.999926757812375">
<font>
<Font name="Arial Bold Italic" size="17.0" />
</font>
</Text>
<TextArea fx:id="TextOfTon" layoutX="326.0" layoutY="118.0" prefHeight="82.0" prefWidth="331.0" />
<Text fill="#dbc9e7" layoutX="338.0" layoutY="250.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Индекс Болтона" textAlignment="CENTER" wrappingWidth="304.8786926269531">
<font>
<Font name="Microsoft Sans Serif" size="40.0" />
</font>
</Text>
<Text fill="#dbc9e7" layoutX="312.0" layoutY="432.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Индекс Коркхауза" textAlignment="CENTER" wrappingWidth="348.0787658691406">
<font>
<Font name="Microsoft Sans Serif" size="37.0" />
</font>
</Text>
<Text fill="#dbc9e7" layoutX="312.0" layoutY="667.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Индекс Пона" textAlignment="CENTER" wrappingWidth="348.0787658691406">
<font>
<Font name="Microsoft Sans Serif" size="37.0" />
</font>
</Text>
<Button fx:id="Calc" layoutX="-3.0" layoutY="21.0" mnemonicParsing="false" prefHeight="28.0" prefWidth="78.0" style="-fx-border-color: black;" text="Расчет" textOverrun="CLIP">
<font>
<Font name="Century Gothic Italic" size="17.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="0.6856060669277653" startY="0.23863638892318267">
<stops>
<Stop>
<color>
<Color red="0.30399999022483826" green="0.7599999904632568" blue="0.624627411365509" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.8842105269432068" green="0.7171930074691772" blue="0.7589473724365234" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Button>
</children>
</AnchorPane>
<ImageView fitHeight="276.0" fitWidth="462.0" layoutX="151.0" layoutY="90.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@JawUp1.png" />
</image>
</ImageView>
<ImageView fitHeight="242.0" fitWidth="466.0" layoutX="139.0" layoutY="406.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@DownJaw1.png" />
</image>
</ImageView>
<TextField fx:id="UpT11" layoutX="326.0" layoutY="83.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpLength6" layoutX="443.0" layoutY="302.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT12" layoutX="261.0" layoutY="104.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT13" layoutX="210.0" layoutY="148.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT14" layoutX="182.0" layoutY="191.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT15" layoutX="161.0" layoutY="238.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT16" layoutX="140.0" layoutY="288.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT46" layoutX="118.0" layoutY="459.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT45" layoutX="153.0" layoutY="513.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT44" layoutX="182.0" layoutY="562.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT43" layoutX="218.0" layoutY="605.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT42" layoutX="270.0" layoutY="640.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT41" layoutX="326.0" layoutY="661.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT31" layoutX="379.0" layoutY="661.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT22" layoutX="443.0" layoutY="104.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT23" layoutX="486.0" layoutY="148.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT24" layoutX="514.0" layoutY="191.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT25" layoutX="543.0" layoutY="238.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT26" layoutX="565.0" layoutY="288.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT36" layoutX="565.0" layoutY="459.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT35" layoutX="543.0" layoutY="513.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT34" layoutX="514.0" layoutY="562.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT33" layoutX="478.0" layoutY="605.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownT32" layoutX="428.0" layoutY="640.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpLength3" layoutX="326.0" layoutY="184.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpLength4" layoutX="379.0" layoutY="184.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpLength5" layoutX="415.0" layoutY="238.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpT21" layoutX="379.0" layoutY="83.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpLength2" layoutX="283.0" layoutY="238.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="UpLength1" layoutX="253.0" layoutY="302.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownLength12" layoutX="249.0" layoutY="445.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownLength11" layoutX="271.0" layoutY="505.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownLength10" layoutX="314.0" layoutY="554.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownLength9" layoutX="379.0" layoutY="554.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownLength8" layoutX="428.0" layoutY="505.0" prefHeight="28.0" prefWidth="43.0" />
<TextField fx:id="DownLength7" layoutX="457.0" layoutY="445.0" prefHeight="28.0" prefWidth="43.0" />
<Text fx:id="UpDif1" layoutX="263.0" layoutY="350.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="UpDif2" layoutX="293.0" layoutY="284.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="UpDif3" layoutX="336.0" layoutY="233.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="UpDif5" layoutX="425.0" layoutY="283.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="UpDif4" layoutX="389.0" layoutY="232.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="UpDif6" layoutX="453.0" layoutY="349.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="DownDif12" layoutX="260.0" layoutY="437.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="DownDif7" layoutX="467.0" layoutY="437.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="DownDif8" layoutX="438.0" layoutY="500.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="DownDif11" layoutX="280.0" layoutY="500.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="DownDif9" layoutX="389.0" layoutY="546.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<Text fx:id="DownDif10" layoutX="324.0" layoutY="546.0" strokeType="OUTSIDE" strokeWidth="0.0" text="----" />
<ImageView fitHeight="150.0" fitWidth="200.0" layoutX="39.0" layoutY="718.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fitHeight="131.0" fitWidth="271.0" layoutX="642.0" layoutY="708.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@WidthTeethDown.png" />
</image>
</ImageView>
<TextField alignment="CENTER" layoutX="14.0" layoutY="814.0" prefHeight="52.0" prefWidth="149.0" text="Задняя">
<font>
<Font name="Elephant Italic" size="22.0" />
</font></TextField>
<TextField alignment="CENTER" layoutX="14.0" layoutY="752.0" prefHeight="52.0" prefWidth="149.0" text="Передняя">
<font>
<Font size="22.0" />
</font></TextField>
<TextField alignment="CENTER" layoutX="14.0" layoutY="717.0" prefHeight="28.0" prefWidth="149.0" text="Ширина зубной дуги">
<font>
<Font size="13.0" />
</font></TextField>
<Text layoutX="300.0" layoutY="770.0" strokeType="OUTSIDE" strokeWidth="0.0" text="1">
<font>
<Font size="19.0" />
</font></Text>
<TextField alignment="CENTER" layoutX="174.0" layoutY="717.0" prefHeight="28.0" prefWidth="116.0" text="Идеальная">
<font>
<Font size="13.0" />
</font></TextField>
<TextField layoutX="300.0" layoutY="717.0" prefHeight="28.0" prefWidth="116.0" text=" Фактическая">
<font>
<Font size="13.0" />
</font></TextField>
<ImageView fitHeight="168.0" fitWidth="246.0" layoutX="642.0" layoutY="546.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@WidthTeethUp.png" />
</image>
</ImageView>
<TextField fx:id="WidthFront" layoutX="174.0" layoutY="752.0" prefHeight="52.0" prefWidth="116.0">
<font>
<Font size="22.0" />
</font></TextField>
<TextField fx:id="WidthBack" layoutX="174.0" layoutY="813.0" prefHeight="52.0" prefWidth="116.0">
<font>
<Font size="22.0" />
</font></TextField>
<Text layoutX="300.0" layoutY="795.0" strokeType="OUTSIDE" strokeWidth="0.0" text="3">
<font>
<Font size="18.0" />
</font>
</Text>
<Text layoutX="300.0" layoutY="833.0" strokeType="OUTSIDE" strokeWidth="0.0" text="2">
<font>
<Font size="18.0" />
</font>
</Text>
<Text layoutX="300.0" layoutY="860.0" strokeType="OUTSIDE" strokeWidth="0.0" text="4">
<font>
<Font size="19.0" />
</font>
</Text>
<TextField fx:id="PonUp1" layoutX="315.0" layoutY="751.0" prefHeight="25.0" prefWidth="43.0" />
<TextField fx:id="PonUp2" layoutX="314.0" layoutY="813.0" prefHeight="25.0" prefWidth="43.0" />
<TextField fx:id="PonDown1" layoutX="315.0" layoutY="776.0" prefHeight="25.0" prefWidth="43.0" />
<TextField fx:id="PonDown2" layoutX="314.0" layoutY="840.0" prefHeight="25.0" prefWidth="43.0" />
<ImageView fx:id="FullButton" fitHeight="74.0" fitWidth="110.0" layoutX="14.0" layoutY="14.0" onMouseClicked="#Maximized_clicked" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Fullscreen.png" />
</image>
</ImageView>
</children>
</AnchorPane>
Main Application:
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1267, 882);
stage.setTitle("OrtoCalculator(by Dasha Vasileva)");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
