Swing/SecondaryLoop のバックアップ(No.11)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/SecondaryLoop へ行く。
- 1 (2017-04-07 (金) 13:51:51)
- 2 (2017-04-18 (火) 15:07:28)
- 3 (2017-08-22 (火) 15:22:23)
- 4 (2018-09-04 (火) 15:05:09)
- 5 (2020-08-28 (金) 15:51:47)
- 6 (2022-02-16 (水) 16:22:29)
- 7 (2025-01-03 (金) 08:57:02)
- 8 (2025-01-03 (金) 09:01:23)
- 9 (2025-01-03 (金) 09:02:38)
- 10 (2025-01-03 (金) 09:03:21)
- 11 (2025-01-03 (金) 09:04:02)
- category: swing
folder: SecondaryLoop
title: SecondaryLoopを使用してイベント・ディスパッチ・スレッド上で別途イベント・ループを実行する
tags: [SecondaryLoop, InputEvent, JLayer]
author: aterai
pubdate: 2015-10-12T05:29:04+09:00
description: SecondaryLoopを使用して、イベント・ディスパッチ・スレッドをブロックせずに、別スレッドをイベント・ループを実行します。
image:
Summary
SecondaryLoop
を使用して、イベント・ディスパッチ・スレッドをブロックせずに、別スレッドをイベント・ループを実行します。
Screenshot

Advertisement
Source Code Examples
layerUI.setInputBlock(true);
SecondaryLoop loop = Toolkit.getDefaultToolkit()
.getSystemEventQueue().createSecondaryLoop();
Thread worker = new Thread() {
@Override public void run() {
doInBackground();
layerUI.setInputBlock(false);
loop.exit();
}
};
worker.start();
loop.enter();
View in GitHub: Java, KotlinExplanation
上記のサンプルでは、JLayerで指定したコンポーネントへの入力を禁止と同様のJLayer
を使用して任意のコンポーネントへの入力可不可を切り替えていますが、SwingWorker
ではなくSecondaryLoop
を使用してバックグラウンドで処理を実行している間はイベント・ディスパッチ・スレッドをブロックしないよう設定しています。
Reference
- Hidden Java 7 Features – SecondaryLoop @ sellmic.com
- SecondaryLoop (Java Platform SE 8)
- JLayerで指定したコンポーネントへの入力を禁止