私のGUIアプリケーションのウィンドウの1つは、内部に同じコントロールを持つ同様のHBoxで構成されています。私はトップレイヤーパネル(この場合はアンカーペイン)にすべてを集中させたいと思っていました。ここでCSSでJavaFXアンカーペインのアンカーを設定する
はコードです:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Button?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<VBox fx:id="modeWindowPane" alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Current" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Frequency" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Fade In" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Fade Out" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Offset" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Stimulation Time" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</HBox>
</VBox>
</AnchorPane>
あなたは、すべてのHBoxに/左/右下/トップのアンカーがあることがわかります。私は何とかそれらをパラメータ化したい、たとえばCSSを使って自分のFXMLファイルのデフォルトのHBoxプロパティを設定したいと思っていました。しかし、私がもっと多くの情報(チュートリアル、オラクルのリファレンス、スタック)を探し始めると、何も役に立たなかった。
私はすべてのコンポーネントを編集する必要がないかどうか誰かから教えてもらえますか?また、MVCデザインパターンに準拠している必要があります。
'HBox'は親として' VBox'を持っています: 'AnchorPane'プロパティを設定するのは意味がありません。 –
@James_D、FXMLでは、アンカーペインにボックスがある場合は、それらにプロパティを追加することができます。これらは、直接ペインのプロパティよりもアラインメント設定です。 – notmyf4ulty
しかし、それらは 'AnchorPane'では(直接的な)ものではありません。彼らは 'VBox'に入っています。 –