Swing/BlurButton のバックアップ差分(No.7)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/BlurButton へ行く。
- 1 (2013-12-09 (月) 00:54:27)
- 2 (2013-12-09 (月) 13:53:21)
- 3 (2013-12-12 (木) 17:35:41)
- 4 (2014-06-03 (火) 21:26:53)
- 5 (2014-09-30 (火) 01:24:50)
- 6 (2015-01-23 (金) 19:23:11)
- 7 (2016-06-17 (金) 19:44:47)
- 8 (2016-06-17 (金) 22:01:53)
- 9 (2017-09-17 (日) 18:10:39)
- 10 (2018-02-27 (火) 14:26:14)
- 11 (2018-06-02 (土) 16:48:33)
- 12 (2020-04-08 (水) 16:07:26)
- 13 (2021-10-19 (火) 12:56:20)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- title: ConvolveOpでコンポーネントにぼかしを入れる tags: [JButton, ConvolveOp, BufferedImage] author: aterai pubdate: 2013-12-09T00:54:27+09:00 description: ConvolveOpを使って、使用不可状態のJButtonにぼかしを入れます。 --- * 概要 [#s496b23a] `ConvolveOp`を使って、使用不可状態の`JButton`にぼかしを入れます。 #download(https://lh6.googleusercontent.com/-KJB6Hz9n1R0/UqSGnCNV3HI/AAAAAAAAB70/sTyoJce2HZQ/s800/BlurButton.png) * サンプルコード [#pa5f0d91] #code(link){{ class BlurButton extends JButton { private final ConvolveOp op = new ConvolveOp( new Kernel(3, 3, new float[] { .05f, .05f, .05f, .05f, .60f, .05f, .05f, .05f, .05f }), ConvolveOp.EDGE_NO_OP, null); private int iw = -1; private int ih = -1; private BufferedImage buf; public BlurButton(String label) { super(label); //System.out.println(op.getEdgeCondition()); } @Override protected void paintComponent(Graphics g) { if (isEnabled()) { super.paintComponent(g); } else { if (buf == null || iw != getWidth() || ih != getHeight()) { iw = getWidth(); ih = getHeight(); buf = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB); } Graphics2D g2 = (Graphics2D) buf.getGraphics(); Graphics2D g2 = buf.createGraphics(); super.paintComponent(g2); g2.dispose(); g.drawImage(op.filter(buf, null), 0, 0, null); } } @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width += 3 * 3; return d; } } }} * 解説 [#u10c29db] - 上 -- デフォルトの`JButton` - 中 -- `ConvolveOp`を使って、使用不可状態の`JButton`にぼかし -- [http://www.oreilly.co.jp/books/4873112788/ Java Swing Hacks 9. 使用不可状態のコンポーネントをぼかし表示する]から引用 - 下 -- `WindowsLookAndFeel`の場合、右端`1`ドットの表示が乱れる場合があるので、`EdgeCondition`をデフォルトの`EDGE_ZERO_FILL`から、`EDGE_NO_OP`に変更 -- `WindowsLookAndFeel`の場合、これらのぼかしを入れると文字が拡大されて?(左右の`Border`が広いから?)、文字列が省略されてしまうので、`JButton#getPreferredSize()`をオーバーライドして幅を拡大 * 参考リンク [#pbb0935e] - [http://docs.oracle.com/javase/jp/7/api/java/awt/image/ConvolveOp.html ConvolveOp (Java Platform SE 7)] - [http://docs.oracle.com/javase/jp/1.4/guide/2d/spec/j2d-image.fm8.html 5.8.1 イメージ処理操作の使用方法] - [http://www.jhlabs.com/ip/blurring.html Java Image Processing - Blurring for Beginners] - [http://www.oreilly.co.jp/books/4873112788/ Java Swing Hacks 9. 使用不可状態のコンポーネントをぼかし表示する] * コメント [#n46593bb] #comment #comment