Reputation: 1000
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) :
To:
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
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
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
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