Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Focus problem with setModal in JDialog

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic