|
-
Can't get reuuestFocus to work
I'm new to Java and having trouble getting requestFocus to place the cursor in a JtextField. I've written a little program to play with but can't get it to work. What am I'm missing?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class testreplyfocus extends JApplet implements ActionListener
{
JLabel prompt = new JLabel ("Test Request Focus");
JButton but = new JButton("Button");
JTextField text = new JTextField("",10);
FlowLayout flow = new FlowLayout();
public void init()
{
Container con = getContentPane();
con.add(prompt);
con.add(but);
con.add(text);
con.setLayout(flow);
but.addActionListener(this);
text.requestFocus()
}
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
text.requestFocus();
if (source == text)
{
System.out.println ("Worked");
}
}
}
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks