• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing the alignment of text inside a button  RSS feed

 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. I've made a GUI program with afew buttons in it. Each Buttons' text consist of different length of text(eg. aeroplane, apple). My aim is to align the text in the buttons to the left.

I've found a program code that supposedly able to do this. However, it doesn't work for me. Am I using the right code for this? Or is there any other codes that is able to set the alignment for my text?



Thanks in advance
[ September 24, 2007: Message edited by: Adrian Lee ]
 
Frank Bacher
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API says that setHorizontalTextPosition(int textPosition) sets the horizontal position of the text relative to the icon. Take a look at setHorizontalAlignment(int alignment). I think that should fit your needs.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank, thanks for your reply . I did try to use the code. However, it doesn't seem to affect the text in the button.

Could there be other ways of doing this? Sorry for the trouble.
 
Frank Bacher
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried it here and for me it works. Maybe there is another problem with your code. But without the code it is really hard to say what is wrong. So if you could give a bit more information/code it would be easier to help you.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank, Thanks for your help. Unfortunately, I can't paste my codes in here as it is rather long and untidy. Basically, I've done the following to my buttons.



Thanks for taking time to helping out.
 
Frank Bacher
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That tiny part of your code seems to be ok for me. But as mentioned before use instead of .

I'll show you my code and you can try if it works for you.


Does it work for you? If yes, do it that way in your code. If not (besides i'm then not really sure if i understand you right), what exactly does it not what you want it to do?
Is really the alignment the problem or is it for example the margin? If so, you could try a setMargin(new Insets(0,0,0,0)) instead.
[ September 24, 2007: Message edited by: Frank Bacher ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12559
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll probably get a better response in the forum dedicated to GUI problems. I'll move this thread over there.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Frank!

I've made a mistake back then. :roll:

I've changed it to setHorizontalAlignment and it works. Thanks for your time.

Thanks Fred for helping to shift this thread.

Best Regards,
Adrian
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!