Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JCheckBox - align text on left

Posted on 2000-02-24
3
Medium Priority
?
2,053 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
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 if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

604 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