6

I am using the JFoenix library for JavaFX, and I wanted to display the check box label to the left of the box.

From (default) :

enter image description here

To:

enter image description here

Looking at the available methods, this is the only thing that reads as it would work but it does not do anything (I am guessing it is just for other graphics):

checkBox.setContentDisplay(ContentDisplay.LEFT);
// checkBox.setContentDisplay(ContentDisplay.RIGHT);

Is there another method or css styling to get the label on the left? Thank you

Edv Beq
  • 910
  • 3
  • 18
  • 43

3 Answers3

6

Incase someone still facing the same problem, here is the answer

from java code

checkbox.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);

from fxml file

nodeOrientation="RIGHT_TO_LEFT"
2

You can use a label and wrap it with the jfxCheckBox in a HBox like below simple way:

JFXCheckBox jfxCheckBox = new JFXCheckBox();
HBox hBox = new HBox();
Label label= new Label("CHECK BOX");
hBox.getChildren().addAll(label, jfxCheckBox);
hBox.setSpacing(10);

Other way as :

Label lblCheckbox = new Label("CHECK BOX");
lblCheckbox.setGraphic(new JFXCheckBox());
lblCheckbox.setContentDisplay(ContentDisplay.RIGHT);
Keyur Bhanderi
  • 1,524
  • 1
  • 11
  • 17
0

You have to adapt or override the layoutChildren() method of the JFXCheckBoxSkin in order to place the checkbox after its label.

Change the x position of the layoutLabelInArea() method such that the label moves/remains to the left. This can be achieved by removing the boxWidth from the xOffset:

layoutLabelInArea(xOffset, yOffset, labelWidth, maxHeight, checkBox.getAlignment());

Similarly, move the checkbox to the right by adding the labelWidth to the xOffset:

positionInArea(box, xOffset+labelWidth, yOffset, boxWidth, maxHeight, 0, checkBox.getAlignment()
                .getHpos(), checkBox.getAlignment().getVpos());
shaka-b
  • 116
  • 1
  • 5