Results 1 to 5 of 5
- 06-17-2010, 02:50 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
JButton with Icon & text alignment issue
Hi,
I have a JButton with a background image & a text of button.
Now I want a text to be aligned Left & Image should remain at center
text should be on image.
For that I have write,
objButton.setHorizontalAlignment(SwingConstants.EA ST); //for left aligning
objButton.setHorizontalTextPosition(0); // to place text on the image ---- this is working fine
but I am not able to align text to left. It is still showing me at center.
Please help me out....
- 06-17-2010, 04:26 PM #2
What layout are you using? I think only BoxLayout really takes your alignment specification into consideration.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-17-2010, 08:30 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
EAST and 0, are not "proper" parameters. Read the API for the list of the proper variables to be used.
You can't do what you want directly with a JButton since text can only be painted on top of the image in the vertical and horizontal center of the button.
You can try using the JButton as a Container and add a label to it then you can position the label anywhere you want. For example you might do:
Java Code:JButton button = new JButton( new ImageIcon(...) ); button.setLayout( new BorderLayout() ); JLabel label = new JLabel( "text" ); button.add( label );
- 06-17-2010, 08:59 PM #4
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
> I have a JButton with a background image
if you're talking about a paintComponent image,
just use drawString with co-ords left of the image
for your text
- 01-11-2011, 11:10 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Text formatting and alignment according to the printer
By java_fledgeling in forum Advanced JavaReplies: 2Last Post: 06-08-2010, 10:34 AM -
[SOLVED] [newbie] AbstractButton.setText() not setting text within JButton
By jon80 in forum New To JavaReplies: 3Last Post: 05-25-2009, 03:33 AM -
My icon extends my JButton
By hitmen in forum AWT / SwingReplies: 5Last Post: 03-06-2009, 07:49 AM -
Alignment Issue...
By chanduseec in forum JavaServer Faces (JSF)Replies: 1Last Post: 09-30-2008, 06:47 AM -
Help needed in Frames text alignment
By ravjot28 in forum Java AppletsReplies: 2Last Post: 06-27-2008, 04:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks