• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextField Question

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic