JavaFX 2中的GroupBox/TitledBorder? [英] GroupBox / TitledBorder in JavaFX 2?

查看:284
本文介绍了JavaFX 2中的GroupBox/TitledBorder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在 GroupBox

Is there something like a GroupBox or TitledBorder available on JavaFX 2?

感谢任何提示:-)

推荐答案

没有这种标准控件,但是创建自己的控件很容易.这是一个示例实现:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆