Swing/ForceHeavyWeightPopupKey のバックアップ(No.7)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/ForceHeavyWeightPopupKey へ行く。
- 1 (2009-05-11 (月) 16:10:58)
- 2 (2009-05-13 (水) 12:59:21)
- 3 (2009-09-03 (木) 19:02:29)
- 4 (2012-03-24 (土) 00:45:46)
- 5 (2013-01-09 (水) 21:04:47)
- 6 (2013-01-10 (木) 01:38:45)
- 7 (2013-05-26 (日) 05:33:58)
- 8 (2013-06-18 (火) 08:34:11)
- 9 (2013-06-18 (火) 14:05:50)
- 10 (2013-06-18 (火) 17:17:37)
- 11 (2013-08-18 (日) 01:01:13)
- 12 (2013-08-28 (水) 12:23:06)
- 13 (2014-11-01 (土) 00:46:09)
- 14 (2014-11-08 (土) 01:41:12)
- 15 (2014-11-25 (火) 03:03:31)
- 16 (2015-02-02 (月) 17:32:47)
- 17 (2016-05-12 (木) 20:05:06)
- 18 (2017-04-07 (金) 13:51:51)
- 19 (2017-07-31 (月) 18:38:45)
- 20 (2017-10-27 (金) 16:26:13)
- 21 (2017-11-02 (木) 15:34:40)
- 22 (2018-08-01 (水) 21:29:33)
- 23 (2020-08-06 (木) 12:17:15)
- 24 (2021-12-28 (火) 12:18:53)
- 25 (2022-08-20 (土) 22:15:25)
- 26 (2022-10-03 (月) 14:56:24)
- 27 (2022-10-04 (火) 15:56:13)
- 28 (2024-10-28 (月) 00:26:28)
- 29 (2025-01-03 (金) 08:57:02)
- 30 (2025-01-03 (金) 09:01:23)
- 31 (2025-01-03 (金) 09:02:38)
- 32 (2025-01-03 (金) 09:03:21)
- 33 (2025-01-03 (金) 09:04:02)
- 34 (2025-06-19 (木) 12:41:37)
- 35 (2025-06-19 (木) 12:43:47)
TITLE:JToolTipをGlassPane上のコンポーネントで表示する
Posted by aterai at 2009-05-11
JToolTipをGlassPane上のコンポーネントで表示する
`JToolTip
を
GlassPane
`上のコンポーネントに追加した場合でも、手前に表示されるように設定します。主にSwing - ComboBox scroll and selected/highlight on glasspaneを参考にしています。
- &jar;
- &zip;
サンプルコード
//Swing - ComboBox scroll and selected/highlight on glasspane
//http://forums.sun.com/thread.jspa?threadID=5315492
try {
Class clazz = Class.forName("javax.swing.PopupFactory");
Field field = clazz.getDeclaredField("forceHeavyWeightPopupKey");
field.setAccessible(true);
label2.putClientProperty(field.get(null), Boolean.TRUE);
} catch (Exception ex) {
ex.printStackTrace();
}
View in GitHub: Java, Kotlin解説
上記のサンプルでは、ボタンをクリックすると、二つのラベルをもつ`GlassPane
`が表示されます。
- `
111...
`(左)- `
GlassPane
の下に
JTooltip
`が表示される - 親フレームの外に`
JTooltip
`がはみ出す場合は、正常に表示される `ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
`では効果なし?
- `
- `
222...
`(右)- 正常に表示されるように、常に、`
JTooltip
`を重量コンポーネントとして表示している - `
PopupFactory
クラスの
forceHeavyWeightPopupKey
をリフレクションで取得して、
JComponent#putClientProperty
`メソッドで設定 - Swing - ComboBox scroll and selected/highlight on glasspaneの`
GlassPane
で
JComboBox
`のポップアップを正常に表示する方法を引用 - `
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
`としておかないと前面に表示されない環境がある?
- 正常に表示されるように、常に、`
`JDK 1.7.0
の場合は、
javax.swing.PopupFactory.forceHeavyWeightPopupKey
`が無くなってしまったので、以下のように
`javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP
`を使用します。
Class clazz = Class.forName("javax.swing.ClientPropertyKey");
Field field = clazz.getDeclaredField("PopupFactory_FORCE_HEAVYWEIGHT_POPUP");
field.setAccessible(true);
combo.putClientProperty(field.get(null), Boolean.TRUE);
参考リンク
- Swing - ComboBox scroll and selected/highlight on glasspane
- JComboBox の GlassPane 上でのレンダリング
- Swing - Why glass pane requires setLightWeightPopupEnabled(false)?
- JInternalFrameをModalにする