The Artima Developer Community
Sponsored Link

Java Answers Forum
How to limit the size of a JTextField?

1 reply on 1 page. Most recent reply: Apr 4, 2002 11:40 PM by steve strongheart

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Avin Sinanan

Posts: 28
Nickname: avin
Registered: Feb, 2002

How to limit the size of a JTextField? Posted: Mar 31, 2002 2:56 AM
Reply to this message Reply
Advertisement
Hello,
I was wondering how to limit the size of a JTextfield to say 5 characters so that onlt 5 letters can fit.

The code does not work ;

JTextField field = new JTextField(5) ;

why doesn't this work?

any suggestions?

yours respectfully Avin Sinanan


steve strongheart

Posts: 12
Nickname: stronghear
Registered: Apr, 2002

Re: How to limit the size of a JTextField? Posted: Apr 4, 2002 11:40 PM
Reply to this message Reply
I've experienced some bugginess with JTextfield too sometimes, try

tf = new JTextField("",5);
or tf.setColumns(5);

You might want to change to a fixed width font.
The TextField might fit 5 M's and 20 1's or l's in a varible width font.

Java makes no garauntee, since many languages have characters whose width changes based on the surrounding letters, meaning of the word and you have to allow for some thermal expansion.

~S~

Flat View: This topic has 1 reply on 1 page
Topic: Java.exe - Application error Previous Topic   Next Topic Topic: java applets and HTML

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use