gpt4 book ai didi

java - 如何禁用 JavaFX 中的最大化选项?

转载 作者:行者123 更新时间:2023-12-02 02:00:54 25 4
gpt4 key购买 nike

我正在创建一个 JavaFX 程序。我已经使用 .fxml 代码来设计页面,但有一个问题,每当我运行程序时,它都可以在默认高度和宽度下正常工作,但是当我最大化该结果时,按钮和其他内容仍保持在默认高度的原始位置和宽度。他们没有调整高度和宽度。因为它是一个mp3播放器并且可以执行一些其他小功能,所以我希望它的大小不应该是可扩展的(它不能最大化)。这也能解决我的问题。

.fxml代码

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<GridPane alignment="top_left" hgap="10" prefHeight="475.0" prefWidth="800.0" style="-fx-background-color: white;" vgap="10" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
</rowConstraints>
<children>
<Label prefHeight="49.0" prefWidth="800.0" text="Spotify Downloader Music Player">
<font>
<Font name="Comic Sans MS" size="24.0" />
</font>
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin></Label>
<GridPane GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="392.0" minWidth="10.0" prefWidth="253.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="551.0" minWidth="10.0" prefWidth="391.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="551.0" minWidth="10.0" prefWidth="217.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button mnemonicParsing="false" prefHeight="30.0" prefWidth="275.0" text="Home">
<font>
<Font size="14.0" />
</font>
</Button>
<Button mnemonicParsing="false" prefHeight="45.0" prefWidth="257.0" text="Playlist" GridPane.rowIndex="1">
<font>
<Font size="14.0" />
</font>
</Button>
<Button mnemonicParsing="false" prefHeight="47.0" prefWidth="257.0" text="Settings" GridPane.rowIndex="2">
<font>
<Font size="14.0" />
</font>
</Button>
<Button mnemonicParsing="false" prefHeight="51.0" prefWidth="257.0" text="About" GridPane.rowIndex="3">
<font>
<Font size="14.0" />
</font>
</Button>
<Label prefHeight="33.0" prefWidth="253.0" text="Music name" GridPane.columnIndex="1">
<font>
<Font size="14.0" />
</font>
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Label>
<TextField prefHeight="34.0" prefWidth="543.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font size="14.0" />
</font>
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</TextField>
<Button mnemonicParsing="false" text="Search" GridPane.columnIndex="2" GridPane.rowIndex="1">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Button>
</children>
</GridPane>
</children>
</GridPane>

如何禁用 JavaFX 中的最大化选项?

如何通过尺寸扩展改变内容位置?

最佳答案

如果您设置resizable propertyStage 设置为 false 它会禁用最大化按钮,同时保留最小化按钮。

public class Main extends Application {
@Override
public void start(Stage primaryStage) {
// Create Scene and add it to primaryStage
primaryStage.setResizable(false);
primaryStage.show();
}
}

这只会阻止用户调整 Stage 的大小,但不会阻止您(开发人员)以编程方式调整 Stage 的大小。

Defines whether the Stage is resizable or not by the user. Programatically you may still change the size of the Stage. This is a hint which allows the implementation to optionally make the Stage resizable by the user.

Javadoc 表明这只是实现的提示。不过,我只能在 Windows 10 计算机上对此进行测试,但您在问题评论中提到它可以在 Linux 计算机上运行。

关于java - 如何禁用 JavaFX 中的最大化选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51599065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com