Swing/TabThumbnail のバックアップソース(No.13)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/TabThumbnail へ行く。
- 1 (2006-07-31 (月) 12:28:44)
- 2 (2006-07-31 (月) 20:18:30)
- 3 (2007-08-05 (日) 21:41:21)
- 4 (2008-06-17 (火) 17:48:29)
- 5 (2010-11-21 (日) 00:28:08)
- 6 (2012-12-16 (日) 23:56:22)
- 7 (2013-02-27 (水) 13:46:49)
- 8 (2015-01-22 (木) 20:46:43)
- 9 (2015-01-23 (金) 19:19:31)
- 10 (2015-03-18 (水) 18:50:25)
- 11 (2017-01-26 (木) 17:56:26)
- 12 (2017-12-19 (火) 16:23:11)
- 13 (2018-10-30 (火) 16:35:11)
- 14 (2020-10-30 (金) 02:02:50)
- 15 (2022-09-22 (木) 20:50:58)
--- category: swing folder: TabThumbnail title: JTabbedPaneのサムネイルをJToolTipで表示 tags: [JToolTip, JTabbedPane] author: aterai pubdate: 2006-07-31T12:28:44+09:00 description: ツールチップを使って、JTabbedPaneのサムネイルを表示します。 image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTUz8_Yw-I/AAAAAAAAAmo/wLoOmG5I3oc/s800/TabThumbnail.png --- * 概要 [#summary] ツールチップを使って、`JTabbedPane`のサムネイルを表示します。 #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTUz8_Yw-I/AAAAAAAAAmo/wLoOmG5I3oc/s800/TabThumbnail.png) * サンプルコード [#sourcecode] #code(link){{ class TabThumbnailTabbedPane extends JTabbedPane { private int current = -1; private static final double SCALE = .15; private Component getTabThumbnail(int index) { Component c = getComponentAt(index); Icon icon = null; if (c instanceof JScrollPane) { c = ((JScrollPane) c).getViewport().getView(); Dimension d = c.getPreferredSize(); int newW = (int) (d.width * SCALE); int newH = (int) (d.height * SCALE); BufferedImage image = new BufferedImage( newW, newH, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.scale(SCALE, SCALE); c.paint(g2); g2.dispose(); icon = new ImageIcon(image); } else if (c instanceof JLabel) { icon = ((JLabel) c).getIcon(); } return new JLabel(icon); } @Override public JToolTip createToolTip() { int index = current; if (index < 0) { return null; } JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder()); p.add(new JLabel(getTitleAt(index)), BorderLayout.NORTH); p.add(getTabThumbnail(index)); JToolTip tip = new JToolTip() { @Override public Dimension getPreferredSize() { Insets i = getInsets(); Dimension d = p.getPreferredSize(); return new Dimension( d.width + i.left + i.right, d.height + i.top + i.bottom); } }; tip.setComponent(this); LookAndFeel.installColorsAndFont( p, "ToolTip.background", "ToolTip.foreground", "ToolTip.font"); tip.setLayout(new BorderLayout()); tip.add(p); return tip; } @Override public String getToolTipText(MouseEvent e) { int index = indexAtLocation(e.getX(), e.getY()); String str = (current == index) ? super.getToolTipText(e) : null; current = index; return str; } } }} * 解説 [#explanation] マウスカーソルがタブタイトル上にきた場合、そのタブ内部のコンポーネントを縮小して`JToolTip`に貼り付けています。 * 参考リンク [#reference] - [http://www.bekkoame.ne.jp/~bootan/free2.html デジタル出力工房 絵写楽] - [http://sozai-free.com/ 2000ピクセル以上のフリー写真素材集] - [http://www.icongalore.com/ XP Style Icons - Windows Application Icon, Software XP Icons] * コメント [#comment] #comment #comment