TITLE:JTextFieldのMarginを設定する
#navi(../)
*JTextFieldのMarginを設定する [#m4b2abe7]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2005-06-06~
更新日:&lastmod;

#contents

**概要 [#e2b43068]
JTextField内部の余白を設定します。

#screenshot

**サンプルコード [#h76ab388]
#code{{
Insets m = (Insets) UIManager.get("TextField.margin");
InsetsUIResource iur = new InsetsUIResource(m.top,m.left+5,m.bottom,m.right);
UIManager.put("TextField.margin", iur);

Insets m = field01.getMargin();
Insets margin = new Insets(m.top,m.left+10,m.bottom,m.right);
field01.setMargin(margin);

Border b1 = BorderFactory.createEmptyBorder(0,20,0,0);
Border b2 = BorderFactory.createCompoundBorder(field02.getBorder(), b1);
field02.setBorder(b2);
}}
-&jnlp;
-&jar;
-&zip;

**解説 [#q40dbf8e]
- 上
-- UIManager.put()ですべてのJTextFieldの余白を指定しています。

- 中
-- 一番上 + setMargin()で余白を指定しています。

- 下
-- 一番上 + setBorder()で余白を指定しています。

上記のサンプルでは、それぞれ左余白のサイズのみを変更しています。

**参考リンク [#l13dc690]
-[[JTextField内にアイコンを追加>Swing/IconTextField]]
-[[JComboBoxにアイコンを表示>Swing/IconComboBox]]

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