This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Position text field content left side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Position text field content left side" Watch "Position text field content left side" New topic
Author

Position text field content left side

John Jai
Rancher

Joined: May 31, 2011
Posts: 1776
Hi,

Please help me to show the content of the JText field from the starting point (first letter from left - and in below eg. the "haii" should be visible). I tried setting the alignment to LEFT but it did not work. And the text field will not be enabled.

code -
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40490
    
  28
I tried it and found nothing wrong with it. Your text is longer than the text field, so you only see its right end. Try with shorter text, eg "Campbell", and you can see it appears as |Campbell       |
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10570
    
    9

setCaretPosition(0);


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
John Jai
Rancher

Joined: May 31, 2011
Posts: 1776
Campbell - that is the issue... when the text was bigger I want it to show from the starting position. setCaretPositioin(0) is working fine.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> And the text field will not be enabled.

'horses for courses' - a JLabel would not have had this problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40490
    
  28
Thank you, Maneesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Position text field content left side