List of usage examples for javax.swing JFrame isFocused
public boolean isFocused()
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// w ww . j a va 2 s.c o 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); }