Solved

JCheckBox - align text on left

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoresSpecial  challenge 13 40
wordlen challenge 3 47
advertisement module in core php 4 88
get weblogic logged in user in java 2 41
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

705 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

15 Experts available now in Live!

Get 1:1 Help Now