0

Is there a way to set margin between TitledPane in javafx?

I created multiple titledpanes and put them altogether inside a VBox. I want it to have a gap between each titledpane.

I looked up setMargin() method to achieve it, but it doesn't seem to be exist.

I also tried with css but it is not working at all.

CSS

.titled-pane {   
    -fx-font-weifght: bold;
    -fx-margin: 5;
}

.titled-pane .title {
    -fx-background-color: #990000; 
    -fx-padding:2 3 3 10;
    -fx-margin: 5;
} 
5
  • If you put them in an HBox, could you then set the gap between them?
    – SedJ601
    Jul 1, 2017 at 3:39
  • See: stackoverflow.com/a/33141605/3992939
    – c0der
    Jul 1, 2017 at 5:02
  • 2
    What margin are you asking about? It sounds like you added multiple TitledPanes to some parent... Without details about this the question will probably be unanswerable.
    – fabian
    Jul 1, 2017 at 5:29
  • @fabian, you're correct. I created multiple titledpanes and want to put gap between each other.
    – Ari
    Jul 1, 2017 at 7:52
  • VBox.setMargin(child, value) ??? Jul 1, 2017 at 15:21

1 Answer 1

1

The answer is very basic. When instantiating VBox, declare the spacing too. Example:

VBox vbox = new VBox(5);

The codes above will give 5 pixels gap between children.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.