Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

JTextField setText() does nothing

Thread view: 
jonasmin@gmail.com - 24 Nov 2007 15:10 GMT
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?
Knute Johnson - 24 Nov 2007 17:29 GMT
> I have problem with setting the JTextField text. here you see some of
> my code:
[quoted text clipped - 8 lines]
> 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);
            }
        });
    }
}

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.