설명에서 언급했듯이 프레임을 소유자로 지정하는 모달 대화 상자를 사용하면 대화 상자가 닫힐 때까지 사용자가 프레임에 액세스 할 수 없습니다.
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class BlockUserFromFrame {
BlockUserFromFrame() {
JFrame f = new JFrame("Try to access frame!");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel l = new JLabel("Access frame after dialog disappears!");
l.setBorder(new EmptyBorder(50, 100, 50, 100));
f.add(l);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);
// use a constructor that allows us to specify a parent and modality
JDialog d = new JDialog(f, true);
JLabel l1 = new JLabel("Dismiss dialog to access frame!");
l1.setBorder(new EmptyBorder(20, 100, 10, 100));
d.add(l1);
d.pack();
d.setLocationRelativeTo(f);
d.setVisible(true);
}
public static void main(String[] args) {
Runnable r =() -> {
BlockUserFromFrame o = new BlockUserFromFrame();
};
SwingUtilities.invokeLater(r);
}
}
이 JDialog' ('에서 확장 modal'가. 당신은 당신의 응용 프로그램 이외의 다른 곳을 클릭에서 사용자를 제한 할 수 없습니다 '로 설정 한 경우가 해당 창에 포커스를 제한 할 수 있습니다.이 창문 있다고 가정 모두 같은 JVM에서 생성됩니다 – MadProgrammer
자세한 내용은 [대화 상자 사용 방법] (https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html)을 참조하십시오. – MadProgrammer
답변 해 주셔서 감사합니다! JFrame을 JDialog로 확장해야합니까? 그렇습니다. 다른 창에서 초점을 제한해야합니다. – sebamed