Solved

JCheckBox - align text on left

Posted on 2000-02-24
3
1,908 Views
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 ?
0
Comment
Question by:tom_corc
3 Comments
 
LVL 4

Expert Comment

by:kylar
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"));
checkBoxPanel.add(myCheck);

Sorry I couldn't be more help

Kylar
0
 
LVL 1

Accepted Solution

by:
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.setHorizontalTextPosition(SwingConstants.LEFT);
jCheckBox1.setText("Hello Tom");

Hope, this will meet your requierement.

Cheers,
Jadhav
0
 

Author Comment

by:tom_corc
ID: 2557357
That worked - Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 63
add projects t working set in maven 2 44
What browser will run Java? 7 127
Java pass by reference 3 22
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

726 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