JCheckBox label posiion

Hi...

I want to put the label of my JCheckBox above the "checkBox". Is there a way to do that or I'll need to create a neu JLabel to put over it?

If I need a label, how can I center the checkBox with the label? (I want the checkBox to be under and horizontally in the middle of the text).

[308 byte] By [Leo77a] at [2007-11-27 7:41:50]
# 1
Read the API docs. there are text alignment methods in JCheckBox (or it's superclass)
bsampieria at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 2
you mean http://java.sun.com/javase/6/docs/api/javax/swing/JCheckBox.html ?Im taking a look a this...
Leo77a at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 3
Now I want to increase he space betwen the button and the text.how do I do that?
Leo77a at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 4
> Now I want to increase he space betwen the button and the text. how do I do that? By reading the API. There is a method that allows you to control the gap between the icon and text.
camickra at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 5
I've seen that method... ( setIconTextGap(1000); )I didnt noticed any difference...Isnt this method to separate the icon and the text? I want to separate the checkBox from the text, not from an Icon I dont have...Message was edited by: Leo77
Leo77a at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 6
> I've seen that method... ( setIconTextGap(1000); )> I didnt noticed any difference...Try setMargin(Insets m)[]'s
Danniel_Williana at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 7
the checkbox part is an icon
bsampieria at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 8

> I've seen that method... ( setIconTextGap(1000); ) I didnt noticed any difference...

Works fine for me.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 9
> I've seen that method... ( setIconTextGap(1000); )> I didnt noticed any difference...Maybe it only works when the text is to the right of the check mark. See the UI delegate for the checkbox on how is the layout implemented.
kirillga at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 10

> Maybe it only works when the text is to the right of the check mark

Don't guess. Try it!

Like I said, it works for me.

Unless actual code is posted why waste time guessing what the OP is doing wrong. Thats why I always ask for a SSCCE, so we don't waste time guessing, wondering what strange code the OP might be using.

If it doesn't work, then maybe its a platform issue or a LAF issue but we won't know unless a SSCCE is posted.

camickra at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...
# 11
It wasn't working because of a bug in the L&F I was using...the "gap" method works fine...thanks for the answers
Leo77a at 2007-7-12 19:22:33 > top of Java-index,Desktop,Core GUI APIs...