Focus problem using JOptionPane.showInternalMessageDialog
Hitesh P Patel
Greenhorn
Joined: May 23, 2012
Posts: 8
posted
0
I have JFrame, which contain JInternalFrame. JInternalFrame contains 3 labels, 3 textfield and 2 buton.
When user after entering details in textfield click OK, if any of the textfield is left blank a message is displayed and focus should return to that textfield.
When JOptionPane.showMessageDialog is used it works perfect, it display message and focus return to empty textfield.
The problem is when using JOptionPane.showInternalMessageDialog it display message and focus remain on OK button.
Please help and let me know what i am missing in the code.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
if it works fine for one, but not the other, why waste your time on 'the other'?
Hitesh P Patel
Greenhorn
Joined: May 23, 2012
Posts: 8
posted
0
Yes it true, but there is two thing.
First : look of message dialog using showMessageDialog and showInternalMessageDialog is different.
Second : I want to know why its not working. I tried but cant figure out the problem, so i posted the same here to get help.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
1) looks like showInternalMessageDialog inherits the L & F of its parent.
it needs a parent (try null as parent) whereas the showMessageDialog doesn't.
2) you'd need to dig into the source codes of both to see what's different.
simple fix is to add the earlier line
Message = ValidateForm();
after the optionPane. having it the second time will only handle the focus request.
Hitesh P Patel
Greenhorn
Joined: May 23, 2012
Posts: 8
posted
0
1) looks like showInternalMessageDialog inherits the L & F of its parent.
it needs a parent (try null as parent) whereas the showMessageDialog doesn't.
2) you'd need to dig into the source codes of both to see what's different.
simple fix is to add the earlier line
Message = ValidateForm();
after the optionPane. having it the second time will only handle the focus request.
It works that ways and already tried before posting code for help.
It will not be good programming to call the routine twice for focus, but for temporary solution i will go with it until I find any solution.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
here's another way, moving the focus request
Hitesh P Patel
Greenhorn
Joined: May 23, 2012
Posts: 8
posted
0
Its better solution then calling the routine twice.