JCheckbox change the text position

Adi Mor picture Adi Mor · Dec 14, 2011 · Viewed 12.7k times · Source

How do i change the position of the text in JCheckbox. I want the text to be on the left of the check box and not as default on the right. i been over the jcheckbox, jtooglebutton and jabstractButton api few times.

Answer

Gnoupi picture Gnoupi · Dec 14, 2011
jCheckBox.setHorizontalTextPosition(SwingConstants.LEFT);

It's actually inherited from AbstractButton, but you can find this also for JLabels (in this case, it's relative to the icon you may use in the label).

Now this is assuming you want just a particular change on this one component. If your goal is to reverse the direction of all components in your application (for example for a right to left reading), you should probably look into component orientation, with the setComponentOrientation and applyComponentOrientation methods.