GroupBox / TitledBorder in JavaFX 2?

后端 未结 6 774
小鲜肉
小鲜肉 2020-11-28 05:57

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

Thanks for any hint :-)

6条回答
  •  庸人自扰
    2020-11-28 06:40

    Here is a GroupBox implementation based on TitledPane. It provides three methods to set the title, content, and content padding of the GroupBox.

    public final class GroupBox extends Parent {
    
        private StackPane _stackPane;
        private TitledPane _titledPane;
    
        public GroupBox() {
            _stackPane = new StackPane();
            _titledPane = new TitledPane();
            setContentPadding(new Insets(10));
            _titledPane.setCollapsible(false);
            _titledPane.setContent(_stackPane);
            super.getChildren().add(_titledPane);
        }
    
        public GroupBox(String title, Node content) {
            this();
            setText(title);
            setContent(content);
        }
    
        public GroupBox(String title, Node content, Insets contentPadding) {
            this(title, content);
            setContentPadding(contentPadding);
        }
    
        public void setText(String value) {
            _titledPane.setText(value);
        }
    
        public void setContent(Node node) {
            _stackPane.getChildren().add(node);
        }
    
        public void setContentPadding(Insets value) {
            _stackPane.setPadding(value);
        }
    }
    

提交回复
热议问题