以下是使用JavaFX构建的界面的原始视图的屏幕截图。底部的那些按钮在此屏幕尺寸中看起来不错。 Original size window
当窗口设置为全屏时,这是视图。这些按钮不会随着屏幕尺寸的增加而增长。与整个窗口相比,它们看起来很小。
这些按钮是从JFoenix库导入的JFXButtons,包含在HBox内部。我已经将VGrow选项设置为always,但按钮没有HGrow选项。我正在使用Scene Builder开发此GUI。那么如何通过改变屏幕尺寸使这些按钮调整其尺寸(尤其是宽度)。 这是接口的.fxml。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import com.jfoenix.controls.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<bottom>
<VBox prefHeight="90.0" prefWidth="1000.0" spacing="5.0">
<children>
<HBox alignment="CENTER" prefHeight="40.0" prefWidth="200.0" spacing="10.0" stylesheets="@../../bin/application/style1.css" BorderPane.alignment="CENTER" VBox.vgrow="ALWAYS">
<children>
<JFXButton fx:id="playpauseBtn" buttonType="RAISED" layoutX="310.0" layoutY="18.0" HBox.hgrow="ALWAYS" />
<JFXButton fx:id="playpauseBtn1" buttonType="RAISED" layoutX="485.0" layoutY="17.0" />
<JFXButton fx:id="playpauseBtn11" buttonType="RAISED" layoutX="515.0" layoutY="17.0" />
<JFXButton fx:id="playpauseBtn12" buttonType="RAISED" layoutX="485.0" layoutY="17.0" />
<JFXButton fx:id="playpauseBtn111" buttonType="RAISED" layoutX="515.0" layoutY="17.0" />
</children>
</HBox>
<JFXSlider prefHeight="21.0" prefWidth="1000.0" VBox.vgrow="ALWAYS">
<padding>
<Insets bottom="8.0" />
</padding></JFXSlider>
</children>
</VBox>
</bottom>
</BorderPane>
答案 0 :(得分:0)
我唯一可以想到的是将这些按钮的宽度和高度绑定到场景的宽度和高度。例如:
playpauseBtn.scaleXProperty().bind(playpauseBtn.getScene().widthProperty().multiply(0.5));
playpauseBtn.scaleYProperty().bind(playpauseBtn.getScene().heightProperty().multiply(0.5));