• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem-Focus on two JTextField at a time

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am facing critical problem in the follwing application. The problem is at a point two text fields getting request foucs. So I unable to edit the one.
code>>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TestFocus extends JFrame
{
JTextField txtOne,txtTwo,txtThree;
JButton btnSet;
TestFocus()
{
txtOne = new JTextField(15);
txtTwo = new JTextField(15);
btnSet = new JButton("Set");
btnSet.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
setClicked();
}
});
this .getContentPane().setLayout(new FlowLayout());
getContentPane().add(txtOne);
getContentPane().add(txtTwo);
getContentPane().add(btnSet);
setSize(200,150);
setLocation(150,150);
setVisible(true);
}
void setClicked()
{
int out = JOptionPane.showConfirmDialog(this,"Do you want exit?", "choose one", JOptionPane.YES_NO_OPTION);
if(out == 0)
{
String sOne = txtOne.getText();
String sTwo = txtTwo.getText();
if(sOne.equals(""))
{
JOptionPane.showMessageDialog(this, "One is empty", "information", JOptionPane.INFORMATION_MESSAGE);
txtOne.requestFocus();
}
else if(sTwo.equals(""))
{
JOptionPane.showMessageDialog(this, "Two is empty", "information",JOptionPane.INFORMATION_MESSAGE);
txtTwo.requestFocus();
}
else
{
System.exit(0);
}
}
}
public static void main(String[] args)
{
new TestFocus();
}
}
Do the following steps,
1.Enter some values in the first text field.click on the set button with out entering any values in the second text field.
2.This will popup a dialog with "Do you want to exit?".
3.click on the yes button. This will popup a another optionpane with the message that "Two is empty". Click ok, the focus will go to second text area.
4.DON'T ENTER ANYTHING IN THE TEXTFIELDS JUST CLICK ON THE FIRST TEXT FIELD AND THEN CLICK THE SET BUTTON.
5.This will popup message as in the 2nd and 3rd step but in the end you can see both the textfiels got focus.
I can't enter any values in the first textfield after that.
I am running this code on Windows2000,jdk1.3.1
selva
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This bug is in Sun's bug database here. It has been fixed in 1.4, and there are a few workarounds for 1.3 that various people have posted in the thread under the bug report.
 
Selvakumar Dharmaraj
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your guidence.
selva.
reply
    Bookmark Topic Watch Topic
  • New Topic