• Post Reply Bookmark Topic Watch Topic
  • New Topic

Customise alignment of text in JTextField  RSS feed

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends, sir, madam
I want to align the text in the JTextField. I studied the setHorizontalAlignment method of JTextField but I still want the text to be more left aligned than the one it does using the above method.

Can anyone tell me how can I do this ? Or which method I need to override from JTextField so that I can customise the position of the text in the JTextField.

Waiting for your suggestions

Thanks and Regards
Rohit.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the "Methods inherited from class javax.swing.text.JTextComponent" section of the JTextField api I see a setMargin method that may help.
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou very much for your reply. I tried that and now the text is getting aligned to extreme left. But I also want the text to be in the top most part. In short North West direction. Right now it is getting aligned to extreme left but not in the top most position.

I passed null as parameter to setMargin which is equvivalent to new Insets(0,0,0,0). But still it is not getting aligned to topmost part of the textfield.

I also tried setting new Insets(0,0,5,0) but still the same effect.

Waiting for your reply.

Thanks and Regards
Rohit.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a million Craig. It is working as expected. Thanks very much

Thanks and Regards
Rohit
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!