Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField Question  RSS feed

 
Mark Mokris
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GUI app with somes JTextFields. The text displayed or entered in these fields really "butts up" against the left edge of the field border. I would like to introduce a slight margin, maybe just a couple pixels.
Is that possible? I can't find it in my Swing docs.
Thanks!
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
This is just a suggestion (I haven't tried it myself). Put an "empty" border on your "JTextField". More details here (in case you didn't already know):
http://java.sun.com/products/jfc/tsc/articles/borders/index.html
http://java.sun.com/docs/books/tutorial/uiswing/misc/border.html
Hope this helps.
Good Luck,
Avi.
 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what ever text u want to display in the text field
accept that in a string.
String str = "Hello World";
String str1 = " "+str;
textfield1.setText(str1);
But this will give u space only on left side of the
textfield.
If u want the make the border on all the four side then try the first reply.
 
Dorothy Finkel-Laverty
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about if you added a few spaces before & after the text field, and then setHorizontalAlignment(JTextField.CENTER).
Not so elegant, but fast!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!