基于 James_D 的解决方案(如何在 JavaFX TitledPane 中设置/删除插图)我已经尝试过,似乎通过 CSS 从 JavaFX TitledPane 中删除插入不起作用?它确实在场景生成器中正确更新,但在运行时插图保持不变。即使 Scenic View 8.0 也报告填充值为 9.6。
FXML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" stylesheets="@newCascadeStyleSheet.css" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="test3.FXMLDocumentController">
<children>
<Accordion layoutX="14.0" layoutY="14.0" prefHeight="270.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<panes>
<TitledPane animated="false" text="untitled 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Button fx:id="button" layoutX="9.600000381469727" layoutY="9.600000381469727" prefHeight="124.0" prefWidth="318.0" text="Click Me!" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="untitled 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane animated="false" text="untitled 3">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
</panes>
</Accordion>
</children>
</AnchorPane>
CSS:
.titled-pane {
-fx-text-fill: rgb(0,100,157);
}
.titled-pane:focused {
-fx-color: -fx-base;
-fx-text-fill: white;
}
.titled-pane > .title {
-fx-text-fill: rgb(0,100,157);
-fx-font-weight: bold;
}
titled-pane > .title > .label{
-fx-text-fill: rgb(0,100,157);
-fx-font-weight: bold;
}
.titled-pane:focused > .title {
-fx-color: rgb(0,100,157);
-fx-text-fill: white;
}
.titled-pane > .title:hover {
-fx-color: lightgrey;
}
.titled-pane > * > * > AnchorPane {
-fx-padding: 0px ;
}
在场景生成器中查看:(预览)
运行时查看:
所以看来由于某种原因没有应用填充。在我的主要应用程序中,我使用了很多Accordion
容器。另一种选择是将 FXML 代码中的填充添加到AnchorPane
of the TitledPane
,这可行,但是是一项耗时的工作。我在 CSS 中遗漏了什么吗?
Set the -fx-padding
对于以下样式类为 0。
.titled-pane .content AnchorPane {
-fx-padding: 0px;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)