Edv Beq
Edv Beq

Reputation: 1000

Label to the left of checkbox with JFoenix in JavaFX

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

Upvotes: 7

Views: 2333

Answers (3)

Sodrul Amin Shaon
Sodrul Amin Shaon

Reputation: 405

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"

Upvotes: 7

shaka-b
shaka-b

Reputation: 116

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());

Upvotes: 0

Keyur Bhanderi
Keyur Bhanderi

Reputation: 1544

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);

Upvotes: 2

Related Questions