• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with JDialog (urgent) please help

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i have some combo boxes and textfields.
in textfield focus lost i am validating the value if invalid i am showing jDailog to show the message.
i am in textfield and enterdrd invalid data and with mouse clicked on the combo.then it is showing the jDailog but on click of o.k on the dailog box.the combo is getting expanded.
but i have to set the focus back to textfield.i am doing textfield.requestFocus() ,but its not working
please help.
[ April 03, 2002: Message edited by: kishore kallam ]
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kishore,
iam a little bit confused with ur explanation,
can u post the code here,so that we can take a look at it and,probably will be able to understand it more clearly.
Raj
 
kishore kallam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply
the actual problem is.
there is one text field and combo.
i am entering some value into textfield and with mouse i clicked on combo.
so first focus lost of textfield will be fired and then mouse click on combo.right.
then on focus lost i am showing error Dialog(it has only o.k button).
what is happening it shows error meassage and on click of o.k it is going to combo even i say textfield.requestfocus().
code:
if (!(val.isAlphaNumeric(txtfState.getText().trim()))) {
errorDialog.errorDialog(15019, 'E');
errorDialog.setLocationRelativeTo(this);
errorDialog.show();
txtfState.requestFocus(); // setting back the focus
validateFlag = false;
}
but it is going to combo
please help
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kishore,
i tried as per ur explanation and it worked fine for me..
i hope this is what u need.
do check out this code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class focusevent extends JFrame
{
JTextField tf;
JComboBox cm;
JDialog dialog;
JButton ok;
Container cont;
focusevent()
{
cont = getContentPane();
tf = new JTextField(10);
cm = new JComboBox();
dialog = new JDialog();
dialog.setSize(150,100);
ok = new JButton("ok");
dialog.getContentPane().add(ok);
cm.addItem("1");
cm.addItem("2");
cont.add(tf);
cont.add(cm);
cont.setLayout(new FlowLayout());
tf.addFocusListener(new focuslistener());
ok.addActionListener(new actionListener());
}
class focuslistener extends FocusAdapter
{
public void focusLost(FocusEvent fe)
{
dialog.setVisible(true);
}
}

class actionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(ok))
{
dialog.dispose();
tf.requestFocus();
}
}
}
public static void main(String a[])
{
focusevent fc = new focusevent();
fc.setSize(300,250);
fc.setVisible(true);

}
}

cheers,
Raj
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using a JTextField, why not use a PlainDocument to do your validation?
 
kishore kallam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi rajendar
in your example you can observe that even dailog box is there ytou can still cange the combo box values.
my requirement is we should not select any of the other components when on click of o.k we are setting focus back to textfield.
this problem exists in you code also.
can you see this and help me please.
 
kishore kallam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Stevens:
If you are using a JTextField, why not use a PlainDocument to do your validation?



thanks paul but its requirement that we need to do on focus lost.
can you help on this
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi kishore,
if u want that ,u dont want focus on other components when u got that 'Dialog' then u need to make that dialog a Modal one.
so modify the line
dialog = new JDialog();
to
dialog = new JDialog(this,true);
this will sort the error .
Raj
 
kishore kallam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
this works fine.but still problem exists.
when you enterd something invalid in textfield and with mouse you click on combo.then what happens first error dialog will come and on click of o.k on that it expands combo because you clicked on combo.
i have to restrict that
is there any way?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic