Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTextField setText() does nothing

Reply
Thread Tools

JTextField setText() does nothing

 
 
jonasmin@gmail.com
Guest
Posts: n/a
 
      11-24-2007
I have problem with setting the JTextField text. here you see some of
my code:

if (in1.getText().length() > 10){
JOptionPane.showMessageDialog(null, "Error", "Error",
JOptionPane.WARNING_MESSAGE);
in1.setText("");
}


in1 - JTextField. But when i axecute the program it does nothing. It
shows the WARNING_MESSAGE, but it does nothing with text. where can be
the problem?
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      11-24-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have problem with setting the JTextField text. here you see some of
> my code:
>
> if (in1.getText().length() > 10){
> JOptionPane.showMessageDialog(null, "Error", "Error",
> JOptionPane.WARNING_MESSAGE);
> in1.setText("");
> }
>
>
> in1 - JTextField. But when i axecute the program it does nothing. It
> shows the WARNING_MESSAGE, but it does nothing with text. where can be
> the problem?


JOptionPane.showMessageDialog is modal so the in1.setText() won't get
executed until the dialog is closed.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame("test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField tf = new JTextField("Hello World");
f.add(tf,BorderLayout.CENTER);
JButton b = new JButton("Erase The Text");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JOptionPane.showMessageDialog(
null,"Error","Error",
JOptionPane.WARNING_MESSAGE);
tf.setText("");
}
});
f.add(b,BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
});
}
}

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re module: Nothing to repeat, but no sre_constants.error: nothing torepeat ? Devin Jeanpierre Python 2 02-14-2012 01:33 PM
Can't Copy text unless console is opened before applet with JTextField in Sun's JVM =?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?= Java 2 07-23-2003 10:28 AM
GridBagLayout and JTextField me Java 2 07-21-2003 02:59 PM
JTable + JTextField Andrew Tucker Java 0 07-17-2003 12:35 PM
JTextField JPassword Peter Java 0 07-11-2003 09:13 AM



Advertisments