Swing/IconScrollBar のバックアップの現在との差分(No.3)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/IconScrollBar へ行く。
- 1 (2006-06-26 (月) 12:08:46)
- 2 (2007-03-29 (木) 23:14:45)
- 3 (2007-10-24 (水) 00:31:50)
- 4 (2012-08-07 (火) 16:18:18)
- 5 (2013-02-28 (木) 14:32:13)
- 6 (2014-11-22 (土) 03:59:58)
- 7 (2014-11-27 (木) 01:47:20)
- 8 (2016-01-12 (火) 17:48:11)
- 9 (2017-06-22 (木) 10:45:24)
- 10 (2018-05-31 (木) 14:33:12)
- 11 (2020-05-27 (水) 02:44:10)
- 12 (2021-11-12 (金) 13:55:35)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:ScrollBarの表示を変更 #navi(../) *ScrollBarの表示を変更 [#l19c9133] >編集者:[[Terai Atsuhiro>terai]]~ 作成日:2006-06-26~ 更新日:&lastmod; --- category: swing folder: IconScrollBar title: ScrollBarの表示を変更 tags: [JScrollBar, JScrollPane] author: aterai pubdate: 2006-06-26T12:08:46+09:00 description: JScrollPaneから縦JScrollBarを取得し、そのノブ上にアイコンを追加表示します。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTOPy62F7I/AAAAAAAAAcE/M4J9GIXdfBY/s800/IconScrollBar.png --- * 概要 [#summary] `JScrollPane`から縦`JScrollBar`を取得し、そのノブ上にアイコンを追加表示します。 #contents #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTOPy62F7I/AAAAAAAAAcE/M4J9GIXdfBY/s800/IconScrollBar.png) **概要 [#w5083920] JScrollBarのバー表示を変更します。 * サンプルコード [#sourcecode] #code(link){{ class BasicIconScrollBarUI extends BasicScrollBarUI { @Override protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds) { super.paintThumb(g, c, thumbBounds); Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color oc = null; Color ic = null; JScrollBar sb = (JScrollBar) c; if (!sb.isEnabled() || thumbBounds.width > thumbBounds.height) { return; } else if (isDragging) { oc = SystemColor.activeCaption.darker(); ic = SystemColor.inactiveCaptionText.darker(); } else if (isThumbRollover()) { oc = SystemColor.activeCaption.brighter(); ic = SystemColor.inactiveCaptionText.brighter(); } else { oc = SystemColor.activeCaption; ic = SystemColor.inactiveCaptionText; } paintCircle(g2, thumbBounds, 6, oc); paintCircle(g2, thumbBounds, 10, ic); g2.dispose(); } #screenshot **サンプルコード [#r85d249f] #code{{ scrollPane.getVerticalScrollBar().setUI(new WindowsScrollBarUI() { protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { super.paintThumb(g,c,thumbBounds); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color oc = null; Color ic = null; JScrollBar sb = (JScrollBar)c; if (!sb.isEnabled() || thumbBounds.width>thumbBounds.height) { return; }else if(isDragging) { oc = SystemColor.activeCaption.darker(); ic = SystemColor.inactiveCaptionText.darker(); }else if(isThumbRollover()) { oc = SystemColor.activeCaption.brighter(); ic = SystemColor.inactiveCaptionText.brighter(); }else{ oc = SystemColor.activeCaption; ic = SystemColor.inactiveCaptionText; } paintCircle(g2,thumbBounds,6,oc); paintCircle(g2,thumbBounds,10,ic); } private void paintCircle(Graphics2D g2, Rectangle thumbBounds, int w, Color color) { g2.setPaint(color); int ww = thumbBounds.width-w; g2.fillOval(thumbBounds.x+w/2, thumbBounds.y+(thumbBounds.height-ww)/2, ww,ww); } }); private void paintCircle(Graphics2D g2, Rectangle b, int w, Color c) { g2.setPaint(c); int ww = b.width - w; g2.fillOval(b.x + w / 2, b.y + (b.height - ww) / 2, ww, ww); } } }} -&jnlp; -&jar; -&zip; **解説 [#p0c5ef9a] 上記のサンプルでは、WindowsScrollBarUIを取得して、垂直スクロールバーに円状のアイコンを表示しています。このためWindowsでは、ドラッグしている状態、カーソルがバー上にあってロールオーバーしている状態、通常の状態でこのアイコンの色が変わります。 * 解説 [#explanation] 上記のサンプルでは、`WindowsScrollBarUI`を取得して垂直スクロールバーに円形アイコンを表示しています。 スクロールバーの長さが足りない場合、アイコンの表示は行われません。 - `WindowsLookAndFeel`が使用されている場合以下の状態の変化に応じてアイコンの色を変更 -- 通常の状態 -- マウスでドラッグ中 -- ロールオーバー中 - スクロールバーの長さが足りない場合このアイコンは表示しない //**参考リンク **コメント [#c32fb82d] * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/plaf/basic/BasicScrollBarUI.html#paintThumb-java.awt.Graphics-javax.swing.JComponent-java.awt.Rectangle- BasicScrollBarUI#paintThumb(...) (Java Platform SE 8)] * コメント [#comment] #comment #comment