jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes Focus problem with setModal in JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus problem with setModal in JDialog" Watch "Focus problem with setModal in JDialog" New topic
Author

Focus problem with setModal in JDialog

Pinto K
Greenhorn

Joined: Nov 11, 2003
Posts: 2
hi all,
Here i created one frame and dialog. when I use "dialog.setModal(true);" , then the focus is not coming to the second button.
ie. "bbut.requestFocus();" not seems working.

But the "bbut.requestFocus();" is working properly,
when i comment the line "dialog.setModal(true);".

How can i set focus to the second button in the JDialog ?
please help.
thanks

The program as follows:

package mypack;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JTextField;

public class FocusTest extends JDialog {

JButton but1,but2;
JButton abut = new JButton("AAA");
JButton bbut = new JButton("BBB");
JTextField textField;
JDialog me;
public FocusTest()
{
me = this;
setSize(300,300);
textField = new JTextField();
textField.setBounds(60,100,100,40);
but1 = new JButton("Test1");
but1.setBounds(10,10,100,30);
but2 = new JButton("Test2");
but2.setBounds(10,60,100,30);
but2.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent mevnt)
{
JDialog dialog = new JDialog(me);
dialog.setModal(true);
dialog.getContentPane().setLayout(null);
abut.setBounds(10,10,100,30);
bbut.setBounds(10,60,100,30);

dialog.getContentPane().add(bbut);
dialog.getContentPane().add(abut);

dialog.setTitle("ChildDlg");
dialog.setLocation(100,100);
dialog.setSize(200,300);
dialog.setVisible(true);
bbut.requestFocus();
}
});
getContentPane().setLayout(null);
getContentPane().add(but1);
getContentPane().add(but2);
getContentPane().add(textField);
setVisible(true);
but2.requestFocus();
}
public static void main(String[] args) {
new FocusTest();
}
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Focus problem with setModal in JDialog