gpt4 book ai didi

JavaFX:在窗口(舞台)上移动元素调整大小

转载 作者:行者123 更新时间:2023-11-29 09:58:40 26 4
gpt4 key购买 nike

我在 JavaFX 上有一个简单的应用程序,它实际上由几个 Pane 和按钮组成。我不知道如何在舞台调整大小时移动按钮。所以,我希望左下角的按钮即使在调整窗口大小时也始终可见。 enter image description here

这里是节点概览:

enter image description here

这里是 fxml:

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

<?import com.jfoenix.controls.JFXButton?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Point3D?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="750.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/9.0.4" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane layoutX="89.0" layoutY="64.0" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<left>
<AnchorPane prefHeight="150.0" prefWidth="150.0" style="-fx-background-color: #4059a9 #4059a9;" BorderPane.alignment="CENTER">
<children>
<AnchorPane prefHeight="750.0" prefWidth="75.0" style="-fx-background-color: #2b4496 #2b4496;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="75.0" AnchorPane.topAnchor="0.0">
<children>
<VBox alignment="CENTER" prefHeight="750.0" prefWidth="75.0" spacing="35.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<JFXButton contentDisplay="GRAPHIC_ONLY" prefWidth="82.0" VBox.vgrow="ALWAYS">
<graphic>
<FontAwesomeIconView fill="WHITE" glyphName="HOME" size="2em" />
</graphic>
<VBox.margin>
<Insets top="25.0" />
</VBox.margin>
</JFXButton>
<JFXButton contentDisplay="GRAPHIC_ONLY" prefWidth="75.0">
<VBox.margin>
<Insets bottom="10.0" top="600.0" />
</VBox.margin>
<graphic>
<FontAwesomeIconView fill="WHITE" glyphName="SIGN_OUT" size="2em" />
</graphic>
<opaqueInsets>
<Insets />
</opaqueInsets>
</JFXButton>
</children>
</VBox>
</children>
<rotationAxis>
<Point3D />
</rotationAxis>
</AnchorPane>
</children>
</AnchorPane>
</left>
</BorderPane>
</children>
</AnchorPane>

最佳答案

看起来你可以通过使用一个 BorderPane 和一个带有叠加背景填充的 VBox 和一个总是插入的 Region 来达到同样的效果在你的按钮之间:

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

<?import com.jfoenix.controls.JFXButton?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.Region?>

<BorderPane prefHeight="750.0" prefWidth="1000.0"
xmlns="http://javafx.com/javafx/9.0.4"
xmlns:fx="http://javafx.com/fxml/1">
<left>
<VBox alignment="TOP_LEFT"
spacing="35.0"
style="-fx-background-color: #2b4496, #4059a9; -fx-background-insets: 0, 0 0 0 75;"> <!-- overlay 2 backgrounds produce rectangles -->
<padding>
<Insets right="75.0" />
</padding>
<children>
<JFXButton contentDisplay="GRAPHIC_ONLY" prefWidth="82.0" VBox.vgrow="NEVER">
<graphic>
<FontAwesomeIconView fill="WHITE" glyphName="HOME" size="2em" />
</graphic>
<VBox.margin>
<Insets top="25.0" />
</VBox.margin>
</JFXButton>
<Region VBox.vgrow="ALWAYS" /> <!-- filler -->
<JFXButton contentDisplay="GRAPHIC_ONLY" prefWidth="75.0" VBox.vgrow="NEVER">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
<graphic>
<FontAwesomeIconView fill="WHITE" glyphName="SIGN_OUT" size="2em" />
</graphic>
</JFXButton>
</children>
</VBox>
</left>
</BorderPane>

关于JavaFX:在窗口(舞台)上移动元素调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54464044/

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