• 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

概要

JButtonをクリックしたときのテキストシフト量を変更します。

サンプルコード

UIManager.put("Button.textShiftOffset", 0);
SwingUtilities.updateComponentTreeUI(this);
View in GitHub: Java, Kotlin

解説

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

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

コメント