내 응용 프로그램은 별도의 스레드에서 JOptionPane 대화 상자를 열 것입니다 타사 독립 실행 형 응용 프로그램과 통합되어 열려있는 모든 대화 상자를 닫으려면 스레드를 실행하고 있습니다. 닫기 전에 내가 얻을 필요가 대화 상자에 쓰여진 메시지.프로그래밍 방식으로 JOptionPane 메시지 내용을 얻는 방법
내가 달성하기 위해 노력하고있는내 샘플 메인 프로그램 :
public static void main(String[] args)throws Exception{
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.scheduleAtFixedRate(() -> {
Window[] possibleWindow = Window.getWindows();
if (possibleWindow != null && possibleWindow.length > 0) {
System.out.println("Found " + possibleWindow.length + "Window(s) " + possibleWindow[0].getClass().getSuperclass());
for (int i = possibleWindow.length - 1; i >= 0; i--) {
try {
Window window = possibleWindow[i];
//here where I need to get the dialog box message before closing it.
window.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, 1, 1, TimeUnit.SECONDS);
JOptionPane.showMessageDialog(null, "test !!!!");
}
당신이 possibleWindow 배열의 모든 참조를위한 JOptionPane의 인스턴스가 될 것이라고 확신? 그렇다면 응용 프로그램에서 Extension (직접 확장 또는 캡슐화에 의해) JOptionPane이 생성 될 때 창 내용을 등록하는 새 클래스를 만드는 것이 더 합리적입니까? 그렇게하면 결국 청소를하려고하지 않을 것입니다. – Teto
방금 확인한 바에 따르면 JOptionPane은 Window의 하위 클래스가 아닙니다. 그래서 나는 그것이 가능한 윈도우 배열에 어떻게 나타나는지를 보지 못했다. 그러나 다른 방법으로 기존 JOptionPane에 대한 참조를 얻을 수 있다면 JOptionPane.getMessage()를 호출하여 메시지 객체를 가져올 수 있습니다. – Teto
내 응용 프로그램은 타사 스윙 독립형 응용 프로그램과 통합되어 있으며 메시지 대화 상자를 표시하는 JOptionPane 객체를 만들지 않았습니다. –