在JavaFX 2.2中隐藏TitledPane的标题 [英] Hide the title of a TitledPane in JavaFX 2.2
问题描述
TitledPane
具有标题。以下是其中几个看起来的样子:
A TitledPane
features a title. Here is how a couple of them can look:
标题为更多..,笑脸和发送。我想完全隐藏发送标题,而不只是删除文本发送。最终结果应该是这样的:
The titles are "More..", "Smileys" and "Send". I want to completely hide the Send title, not just remove the text "Send". The end result should be something like this:
有可能吗?
推荐答案
我会只需使用标准 Pane
作为第三个内容区域而不是 TitledPane
并应用相关样式来欺骗JavaFX进入样式底部面板好像是 TitlePane
的内容区域。
I would just use a standard Pane
for the third content area rather than a TitledPane
and apply the relevant styles to trick JavaFX into styling the bottom panel as if it was the content area of a TitlePane
.
粗略地说,你需要一些FXML标记类似于:
Roughly speaking you will require some FXML markup similar to this:
<VBox styleClass="titled-pane"
xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/2.2" >
<children>
<TitledPane animated="false" text="untitled">
<content>
<AnchorPane minHeight="0.0"
minWidth="0.0"
prefHeight="180.0"
prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane animated="false" text="untitled">
<content>
<AnchorPane id="Content"
minHeight="0.0"
minWidth="0.0"
prefHeight="180.0"
prefWidth="200.0" />
</content>
</TitledPane>
<Pane prefHeight="200.0" prefWidth="200.0" styleClass="content">
<children>
<Button layoutX="74.0"
layoutY="21.0"
mnemonicParsing="false"
text="Button" />
</children>
</Pane>
</children>
</VBox>
这基本上在VBox中放置了三个窗格,以便它们正确堆叠并应用一些样式来分辨JavaFX如何渲染第三个窗格
。
This basically lays the three panes out in a VBox so that they stack correctly and applies some styles to tell JavaFX how to render the third Pane
.
为了实现第三个 Pane
的正确外观,你需要给它一个样式类内容。这是 Pane
的背景名称,它是 TitledPanes
子结构的一部分,并告诉JavaFX渲染窗格与 TitledPane
控件的方式相同。
In order to achieve the correct look of the third Pane
you will need to give it a style class of "content". This is the name of the background Pane
that is part of the TitledPanes
sub-structure and tells JavaFX to render the pane in the same way as the TitledPane
control.
这不会像现实的css定义那样有效看起来像这样:
This will not work as it stands though as the actual css definition looks something like this:
.titled-pane .content { // styles defined here }
这意味着该样式仅适用于样式类为content的节点,如果它们也在节点内样式类标题窗格。
What this means is that the style will only apply to nodes that have a style class of "content" if they are also inside a node with a style class of "titled-pane".
解决这个问题的简单方法是给根容器窗格
(在这种情况下为 VBox
)样式类标题窗格,有效地欺骗JavaFX认为第三个窗格是 titleledPanes
内容区域。
The simple way to fix this is to give the root container Pane
(the VBox
in this case) a style class of "titled-pane", effectively tricking JavaFX into thinking the third pane is a titledPanes
content area.
此输出如下所示:
并且两个 TitledPanes
已折叠:
这篇关于在JavaFX 2.2中隐藏TitledPane的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!