• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JToolTipをGlassPane上のコンポーネントで表示する
#navi(../)
RIGHT:Posted by [[terai]] at 2009-05-11
RIGHT:Posted by &author(aterai); at 2009-05-11
*JToolTipをGlassPane上のコンポーネントで表示する [#d46a12cd]
JToolTipをGlassPane上のコンポーネントに追加した場合でも、手前に表示されるように設定します。主に[[Swing - ComboBox scroll and selected/highlight on glasspane>http://forums.sun.com/thread.jspa?threadID=5315492]]を参考にしています。
JToolTipをGlassPane上のコンポーネントに追加した場合でも、手前に表示されるように設定します。主に[http://forums.sun.com/thread.jspa?threadID=5315492 Swing - ComboBox scroll and selected/highlight on glasspane]を参考にしています。

-&jnlp;
//-&jnlp;
-&jar;
-&zip;

#screenshot
//#screenshot
#ref(http://lh6.ggpht.com/_9Z4BYR88imo/TQTNMeZI4ZI/AAAAAAAAAaY/8XHy9j6jQw0/s800/ForceHeavyWeightPopupKey.png)

**サンプルコード [#f0477f43]
#code{{
//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();
}
}}

**解説 [#rec54369]
上記のサンプルでは、ボタンをクリックすると、二つのラベルをもつGlassPaneが表示されます。
-111...(左)
--GlassPaneの下にJTooltipが表示される
--親フレームの外にJTooltipがはみ出す場合は、正常に表示される
--%%ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); では効果なし?%%
-222...(右)
--正常に表示されるように、常に、JTooltipを重量コンポーネントとして表示している
--PopupFactoryクラスの forceHeavyWeightPopupKey をリフレクションで取得して、JComponent#putClientPropertyメソッドで設定
--[[Swing - ComboBox scroll and selected/highlight on glasspane>http://forums.sun.com/thread.jspa?threadID=5315492]]のGlassPaneでJComboBoxのポップアップを正常に表示する方法を引用
--[http://forums.sun.com/thread.jspa?threadID=5315492 Swing - ComboBox scroll and selected/highlight on glasspane]のGlassPaneでJComboBoxのポップアップを正常に表示する方法を引用
--ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); としておかないと前面に表示されない環境がある?

**参考リンク [#webb6ab8]
-[[Swing - ComboBox scroll and selected/highlight on glasspane>http://forums.sun.com/thread.jspa?threadID=5315492]]
-[[JComboBox の GlassPane 上でのレンダリング>http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?mode=viewtopic&topic=42615&forum=12]]
-[[Swing - Why glass pane requires setLightWeightPopupEnabled(false)?>http://forums.sun.com/thread.jspa?threadID=5245072]]
-[[JInternalFrameをModalにする>http://terai.xrea.jp/Swing/ModalInternalFrame.html]]
-[http://forums.sun.com/thread.jspa?threadID=5315492 Swing - ComboBox scroll and selected/highlight on glasspane]
-[http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?mode=viewtopic&topic=42615&forum=12 JComboBox の GlassPane 上でのレンダリング]
-[http://forums.sun.com/thread.jspa?threadID=5245072 Swing - Why glass pane requires setLightWeightPopupEnabled(false)?]
-[http://terai.xrea.jp/Swing/ModalInternalFrame.html JInternalFrameをModalにする]

**コメント [#n67c57a8]
#comment