2021-11-18 (木) 11:32:21
  • category: swing folder: TextFieldMargin title: JTextFieldのMarginを設定する tags: [JTextField, UIManager, Border] author: aterai pubdate: 2005-06-06T00:34:45+09:00 description: JTextFieldにMargin、または二重のBorderを設定して、内余白の変化をテストします。 image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTVM2PvsXI/AAAAAAAAAnQ/3wxfaHXrEUk/s800/TextFieldMargin.png

概要

JTextFieldMargin、または二重のBorderを設定して、内余白の変化をテストします。
http://terai.xrea.jp/swing/textfieldmargin/screenshot.png

サンプルコード

View in GitHub: Java, Kotlin

解説

以下のサンプルでは、それぞれ左側の内余白のサイズのみを変更しています。
  • 上: UIManager.put()ですべてのJTextFieldの余白を指定
    • getMargin().left: 7px
    • getInsets().left: 8px
    • getBorder().getBorderInsets(c).left: 8px
  • 中: 「上(UIManager.put())」とsetMargin()で余白を指定
    • getMargin().left: 17px
    • getInsets().left: 18px
    • getBorder().getBorderInsets(c).left: 18px
  • 下: 「上(UIManager.put())」とsetBorder()で余白を指定
    • getMargin().left: 7px
    • getInsets().left: 28px
    • getBorder().getBorderInsets(c).left: 28px

参考リンク

コメント