JavaFX Titlemaneでインセットを設定/削除する方法
質問
次のように、単一の子コンポーネント(ボタン)を使用してJavaFXにタイトルパンを作成しました:
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TitledPane animated="false" layoutX="137.0" layoutY="60.0" prefHeight="400.0" prefWidth="600.0" text="untitled" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" >
<children >
<Button layoutX="193.1875" layoutY="133.5" mnemonicParsing="false" prefHeight="374.0" prefWidth="598.0" text="Button" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</children>
</AnchorPane>
.
これは以下のように見えます。ボタンの周りにはかなりの間隔があります。これを行うanchorpaneまたはtitledpaneのいずれかのプロパティはありません。そのような財産はありますか?
解決
Scenic View このような問題を解決するには、
タイトルパン内のアンコーパンには、全面に0.8em(10px)のパディングがあります。これは、デフォルトのスタイルシート、modeNA.CSSで定義されています。FXMLでリセットできます。
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TitledPane animated="false" text="untitled" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane >
<padding>
<Insets top="0" right="0" left="0" bottom="0"/>
</padding>
<children >
<Button mnemonicParsing="false" text="Button" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</children>
</AnchorPane>
.
または
付きの外部スタイルシート付き.titled-pane > * > * > AnchorPane {
-fx-padding: 0em ;
}
. 他のヒント
私はすでにしかし、私はまたこの質問に完全に一致するので、ここでそれを投稿したいのです。
@ james_dの回答を拡張するには:
AnchorPane
のコンテンツとしてTitledPane
を使用しない場合は、それに応じてCSSを調整する必要があります。
一般的なCSSソリューションTitledPane
のコンテンツの種類を除去するための普遍的なCSSソリューションは、どのタイプのNode
が使用されていても、次のものがあります。
.titled-pane > .content > * {
-fx-padding: 0px;
}
.
これは、TitledPane
のコンテンツの任意の子のPADDINGを0px
に設定します。
所属していません StackOverflow