aspose file tools
The moose likes Swing / AWT / SWT and the fly likes JtextField----URGENT!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JtextField----URGENT!!!!!!" Watch "JtextField----URGENT!!!!!!" New topic
Author

JtextField----URGENT!!!!!!

Remi Dubey
Greenhorn

Joined: Jun 12, 2001
Posts: 8
hi,
The problem is related to the handling of the Textfield. I am implementing the KeyTyped method of the KeyListerner Interface. Now whenever a key is pressed and the KeyTyped method is fired. NOw extracting the contents of the TextField at that moment does not pass the updated TextField contents rather the old values which creates lot of problems in subsequent handling of the code.
I am listing down my KeyTyped method so that the problem becomes clear.
Here Inodestf is a JTextField
Problem is the contents of String s which gets the old value of the TextField after the Key is pressed. Suggest a solution to get the updated value in the String s after the KeyListerner event is fired.
public void keyTyped(KeyEvent ke)
{
try
{
if ( (ke.getSource() == Inodestf) )
{ char c=ke.getKeyChar();
String s = Inodestf.getText().trim(); //Contents of TextField not updated
if (Character.isISOControl(c)) // for non printable chars...
{
lv.numinputneurons = Integer.parseInt(s);
}else // for printable chars...
{
lv.numinputneurons = Integer.parseInt(s+c);
currInodes = lv.numinputneurons;
}
}
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Remi,
I think you might be better to look into DocumentListeners when using JTextFields.

The java.awt.TextField could be monitored for changes by adding a TextListener for TextEvent's. In the JTextComponent based
components, changes are broadcasted from the model via a DocumentEvent to DocumentListeners. The DocumentEvent gives the location of
the change and the kind of change if desired. The code fragment might look something like:
DocumentListener myListener = ??;
JTextField myArea = ??;
myArea.getDocument().addDocumentListener(myListener);

Regards,
Manfred.
ashok_dara
Greenhorn

Joined: Jul 01, 2001
Posts: 1
Hi,
I saw the code.
Instead of String use StringBuffer .
If u'r problem is not solved contact me at ashok_dara@rediffmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JtextField----URGENT!!!!!!
 
Similar Threads
Key Events
JTextfield refresh in keypressed event
KeyListener
KeyListerner in JPanel
Setting focus to a dialog button?