나는 사용자가 메인 화면의 아무 곳이나 클릭하면 그 아이에
자식 창에 WindowListener
를 추가 한 후 windowDeactiveated()
이벤트를 처리하고 호출 (거짓)로 setVisible를 사라지게하고 싶습니다 창문.
근무 예 :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DialogDeactivated
{
public static void main(String[] args)
{
final WindowListener wl = new WindowAdapter()
{
public void windowDeactivated(WindowEvent e)
{
e.getWindow().setVisible(false);
}
};
JButton button = new JButton("Show Popup");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
JFrame frame = (JFrame) SwingUtilities.windowForComponent(button);
JDialog dialog = new JDialog(frame, false);
dialog.setUndecorated(true);
dialog.add(new JButton("Dummy Button"));
dialog.pack();
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);
dialog.addWindowListener(wl);
}
});
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(button, BorderLayout.NORTH);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
는 [어디 인 JPanel에/마우스 입력 종료 이벤트를 검출]이 게시물을 참조하시기 바랍니다 (http://stackoverflow.com/questions/2445297/detecting-mouse-enter-exit-events -anywhere-on-jpanel) –