Solved

JCheckBox - align text on left

Posted on 2000-02-24
3
1,869 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 44
Groovy problem when using SOAPUI : DispatchException occurred 7 44
servlet example 11 40
check java version using powershell 13 92
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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