
-----------------------------------
UnusedUsername
Tue Jul 24, 2007 10:57 am

JButton Alignment
-----------------------------------
I want to create JButtons with text positioned to their very left.

I've tried using setHorizontalAlignment(), setHorizontalTextPosition() and setMargins() but none of them can create the desired effect.

Does anyone know how to do this?

-----------------------------------
Aziz
Tue Jul 24, 2007 1:54 pm

RE:JButton Alignment
-----------------------------------
Hmm, good question. Perhaps it's not an alignment iissue, but an issue with the inner borders/padding of buttons?

Try reading the Swing Tutorial:

http://java.sun.com/docs/books/tutorial/uiswing/components/button.html

-----------------------------------
UnusedUsername
Tue Jul 24, 2007 4:33 pm

RE:JButton Alignment
-----------------------------------
After reading it, I don't think it can be done, which is rather odd.

-----------------------------------
rizzix
Tue Jul 24, 2007 4:42 pm

RE:JButton Alignment
-----------------------------------
It is definitely possible.

button.setHorizontalAlignment(SwingConstants.LEFT);

To make it such that the text is positioned to the far left, you'd have to pass appropriate Insets to setMargin(); and reduce the gap to Zero.

-----------------------------------
UnusedUsername
Wed Jul 25, 2007 7:06 am

RE:JButton Alignment
-----------------------------------
I see how it works now. I have to use setAlignment() in conjunction with setMargins(). Thanks for the help guys (or gals).

-----------------------------------
Aziz
Wed Jul 25, 2007 8:42 am

RE:JButton Alignment
-----------------------------------
Guys. Definitely guys. Unless you're hiding something, rizzix? Anyways, glad we could help. Java Tutorials + API documentation (and the occasional google) is one of a java programmer's best assets.
