2016-08-08 3 views
1

私の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デザインパターンに準拠している必要があります。

+0

'HBox'は親として' VBox'を持っています: 'AnchorPane'プロパティを設定するのは意味がありません。 –

+0

@James_D、FXMLでは、アンカーペインにボックスがある場合は、それらにプロパティを追加することができます。これらは、直接ペインのプロパティよりもアラインメント設定です。 – notmyf4ulty

+0

しかし、それらは 'AnchorPane'では(直接的な)ものではありません。彼らは 'VBox'に入っています。 –

答えて

0

JavaFX CSS Reference Guideをご覧ください。そこには、すべてのCSS属性の完全なドキュメンタリーがあります。私が知る限り、CSSを使ってオブジェクトのアンカーを設定することはできません。

コントローラ経由で作成できます。すべてのアイテムにコントローラfx:idを割り当ててください。その後、アンカーを繰り返してアンカーを設定することができます(例:AnchorPane.setTopAnchor(Node, Value))。詳細はAnchorPaneを参照してください。

+0

ありがとう、しかし私はこの参照を知っています。私はそれを読んだが、残念ながらあなたが言っていることは恐れている。私はコントローラーを介してそれが可能であることを認識しています。しかし、私はMVCデザインパターンでプロジェクトをデザインしたいと思っていました。コントローラのレイアウトを編集できるかどうかはわかりません。 – notmyf4ulty

関連する問題