Swing/BlurButton のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - 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でコンポーネントにぼかしを入れる #navi(../) #tags(JButton, ConvolveOp, BufferedImage) RIGHT:Posted by &author(aterai); at 2013-12-09 * ConvolveOpでコンポーネントにぼかしを入れる [#s496b23a] `ConvolveOp`を使って、使用不可状態の`JButton`にぼかしを入れます。 - &jnlp; - &jar; - &zip; #ref(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(); 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/ 9. 使用不可状態のコンポーネントをぼかし表示する]から引用 - 下 -- `WindowsLookAndFeel`の場合、右端`1`ドットの表示が乱れる場合があるので、`EdgeCondition`をデフォルトの`EDGE_ZERO_FILL`から、`EDGE_NO_OP`に変更 -- `WindowsLookAndFeel`の場合、これらのぼかしを入れると文字が拡大してしまう(左右の`Border`が広い)ので、`JButton#getPreferredSize()`をオーパーライドして幅を拡大 ** 参考リンク [#pbb0935e] - [http://www.oreilly.co.jp/books/4873112788/ 9. 使用不可状態のコンポーネントをぼかし表示する] ** コメント [#n46593bb] #comment