JTextfield behaviour
1 posts in topic
Flat View  Flat View

Posted By:   Jon_Jon
Posted On:   Sunday, May 9, 2004 12:41 AM

I have 2 questions concerning the behaviour of JTextFiels objects in a JDialog window:
- how can I limit the number of characters that can be edited in the input box?
- the input is not saved until I type Enter in the field; if I press Tab or I click the mouse on another field nothing seems to happends; I try to save the input in a String variable in the listener function associated with the text field).


Re: JTextfield behaviour

Posted By:   David_Thornton  
Posted On:   Sunday, May 9, 2004 05:57 PM

I have never tried using Swing components in JavaScript but in general the answers to your questions are;

1. Create a document that extends javax.swing.text.PlainDocument and over ride the insertString() method to only allow characters to be inserted up to a specified length.

2. You need to add a Focus Listener to you text field and then handle setting the variable in the focusLost() method.

About | Sitemap | Contact