私のアプリケーションは、別のスレッドで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のインスタンスになることを確信していますか?もしそうなら、アプリケーションの作成時にPaneの内容を登録する新しいクラスを作成するためにJOptionPaneを拡張(直接拡張またはカプセル化によって)する方が適していますか?あなたは最後にクリーンアップしようとしていないだろうそのように。 – Teto
JOptionPaneはWindowのサブクラスではありません。だから私はそれが可能なウィンドウの配列でどのように表示されるのか見ていない。しかし、他の方法で既存のJOptionPaneへの参照を取得できる場合は、JOptionPane.getMessage()を呼び出してメッセージオブジェクトを取得できます。 – Teto
私のアプリケーションはサードパーティのスイングスタンドアロンアプリケーションと統合されており、メッセージダイアログを表示するためにJOptionPaneオブジェクトを作成する必要はありません。 –