JavaFX 2 中的 GroupBox/TitledBorder? [英] GroupBox / TitledBorder in JavaFX 2?
本文介绍了JavaFX 2 中的 GroupBox/TitledBorder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有类似于 GroupBox 或 TitledBorder 在 JavaFX 2 上可用吗?
Is there something like a GroupBox or TitledBorder available on JavaFX 2?
感谢您的任何提示:-)
Thanks for any hint :-)
推荐答案
没有这样的标准控件,但很容易创建自己的控件.这是一个示例实现:
No such standard control, but it it is easy to create your own. Here is a sample implementation:
/** Places content in a bordered pane with a title. */
class BorderedTitledPane extends StackPane {
BorderedTitledPane(String titleString, Node content) {
Label title = new Label(" " + titleString + " ");
title.getStyleClass().add("bordered-titled-title");
StackPane.setAlignment(title, Pos.TOP_CENTER);
StackPane contentPane = new StackPane();
content.getStyleClass().add("bordered-titled-content");
contentPane.getChildren().add(content);
getStyleClass().add("bordered-titled-border");
getChildren().addAll(title, contentPane);
}
}
及其附带的css:
.label {
-fx-font: 28px Vivaldi;
}
.bordered-titled-title {
-fx-background-color: white;
-fx-translate-y: -16;
}
.bordered-titled-border {
-fx-content-display: top;
-fx-border-insets: 20 15 15 15;
-fx-background-color: white;
-fx-border-color: black;
-fx-border-width: 2;
}
.bordered-titled-content {
-fx-padding: 26 10 10 10;
}
代码来自示例,我是为了响应 Oracle JavaFX 论坛帖子而创建的相当于 BorderFactory.createTitledBorder".
The code is from a example I created in response to an Oracle JavaFX forum thread post "Equivalent to BorderFactory.createTitledBorder".
示例程序的输出如下所示.
The output of the example program is as shown below.
这篇关于JavaFX 2 中的 GroupBox/TitledBorder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文