Switch checkbox text and component


Question

I want to create checkbox with text in the left side and the checkbox component on the right side. How I can switch their place?

CheckBox cb = new CheckBox("Show on Startup");
1
3
8/11/2013 9:22:02 PM

Accepted Answer

There might be an easier way, but you can use a label and wrap it with the CheckBox in a HBox:

HBox box = new HBox();
CheckBox cb = new CheckBox();
Label text = new Label("Show on Startup");
box.getChildren().addAll(text, cb);
box.setSpacing(5);
3
8/11/2013 11:11:07 PM

In JavaFX 8, you can do it like this:

Label lb = new Label("left check");
lb.setGraphic(new CheckBox());
lb.setContentDisplay(ContentDisplay.RIGHT); //You can choose RIGHT,LEFT,TOP,BOTTOM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon