• 追加された行はこの色です。
  • 削除された行はこの色です。
---
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
---
* 概要 [#q33481d1]
* 概要 [#summary]
`JButton`をクリックしたときのテキストシフト量を変更します。

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

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

* 解説 [#m09c32c8]
* 解説 [#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`

//* 参考リンク
* コメント [#i782599b]
//* 参考リンク [#reference] [#reference]
* コメント [#comment]
#comment
#comment