JCheckBox - align text on left

Posted on 2000-02-24
Last Modified: 2006-11-17
I have a JCheckbox for which I want the label or caption on the left and the checkbox on the right. I have tried using the setAlignmentX, setHorizontalAlignment and setHorizontalTextPosition methods but they don't seem to work. Does anyone have any sample code for this ?
Question by:tom_corc

Expert Comment

ID: 2555905
I don't think there is an easy way to do this, unfortunately. I think you would have to write your own Checkbox UI. You could probably fake it like this:

JPanel checkBoxPanel = new JPanel(new GridLayout(1,2));

JCheckBox myCheck = new JCheckBox();

checkBoxPanel.add(new JLabel("My CheckBoxText"));

Sorry I couldn't be more help


Accepted Solution

jadrek85 earned 50 total points
ID: 2556662
Hi Tom,
You can do this by setHorizontalTextPosition method. Here is the code for you.

JCheckBox jCheckBox1 = new JCheckBox();
jCheckBox1.setText("Hello Tom");

Hope, this will meet your requierement.


Author Comment

ID: 2557357
That worked - Thanks

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven project error 5 48
more than one jdk and one jre 1 34
windows explorer path to command prompt 5 33
Configure a Bean in an XML file 4 14
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now