• 追加された行はこの色です。
  • 削除された行はこの色です。
---
category: swing
folder: TextShiftOffset
title: JButtonのテキストシフト量を変更
tags: [JButton, UIManager]
author: aterai
pubdate: 2007-12-31T16:51:19+09:00
description: JButtonをクリックしたときのテキストシフト量を変更します。
image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTVR92SsdI/AAAAAAAAAnY/_wKFJTNu2oY/s800/TextShiftOffset.png
---
* 概要 [#summary]
`JButton`をクリックしたときのテキストシフト量を変更します。

#download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTVR92SsdI/AAAAAAAAAnY/_wKFJTNu2oY/s800/TextShiftOffset.png)

* サンプルコード [#sourcecode]
#code(link){{
UIManager.put("Button.textShiftOffset", 0);
SwingUtilities.updateComponentTreeUI(this);
}}

* 解説 [#explanation]
上記のサンプルでは、`JButton`をクリックした際に、あわせて内部の文字列が移動する距離を、`0`、`1`、`-1`と切り替えることができます。

- `JButton`に設定した`Icon`は文字列と同様に移動するが、文字列が`HTML`テキストの場合は無効で移動しない
- `JToggleButton`などには、効果がない
-- `UIManager.put("ToggleButton.textShiftOffset", 1)`なども無効
- `Java 1.5.0` + `WindowsLookAndFeel`のデフォルトは`1`
- `Java 1.6.0` + `WindowsLookAndFeel`のデフォルトは`0`

* 参考リンク [#reference]
- [[ConvolveOpでコンポーネントにぼかしを入れる>Swing/BlurButton]]
-- `ToggleButton.textShiftOffset`を考慮しておかないと、ボタンの端にブラー効果が適用されない?
-- %%`ToggleButton.textShiftOffset`を考慮しておかないと、ボタンの端にブラー効果が適用されない?%% 無関係

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