Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Changing the alignment of text inside a button  RSS feed

 
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 ]
 
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 ]
 
lowercase baba
Bartender
Posts: 12627
50
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!