• 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

Entry limit to Textfields

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all, i wrote some code to check the length of textfields. as i have to save all into a DB, where i've got some varchar(10). the code i have allows you to type only 10 chars into the respective textfield, but my problem is, that if i paste a longer string into it (from clipboard), the textfields accepts it and while i try to save, i get a DB exception that a submitted value is too big. am thankfull for any help.
aa.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes it's happened when u paste at textfeild .......
if u dont need the word longer then 10 chars
my logic is
u have to put this code at the event of button

// tf is the veriable of textfeild
String str = tf.getText();
int i = str.lenght();
if (i<10)
{
System.out.println("ok");
}
esle{
System.out.println("again");
// you have to write under 10
//
}
 
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 Linda,
There is an excellent (in my opinion) example of how to achieve this in "The Java Tutorial" (assuming you haven't already looked at it):
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html#validation
Hope this helps you.
Good Luck,
Avi.
 
linda lichelli
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much. although the java tutorial implementation would be much better as i did now, i chose the way of getting the stringbuffer length and check it before writing to the DB. it's not too proper, but it works for the moment! thx again.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic