List of usage examples for javax.swing JDialog addFocusListener
public synchronized void addFocusListener(FocusListener l)
From source file:Main.java
public static void main(final String[] args) { JFrame frame = new JFrame("Frame"); JDialog dialog = new JDialog(frame, "Dialog"); frame.add(new JLabel("Content")); frame.addMouseListener(new MouseAdapter() { @Override/*from w w w.ja v a2 s . co m*/ public void mousePressed(MouseEvent arg0) { System.out.println("frame pressed"); System.out.println("dialog focused " + dialog.isFocused()); System.out.println("frame focused " + frame.isFocused()); super.mousePressed(arg0); } }); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); dialog.add(new JLabel("Content")); dialog.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { super.focusLost(arg0); dialog.requestFocus(); } }); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }