• 追加された行はこの色です。
  • 削除された行はこの色です。
---
category: swing
folder: MatteBorder
title: MatteBorderでラベル枠を修飾
tags: [MatteBorder, JLabel]
author: aterai
pubdate: 2004-12-20T00:29:03+09:00
description: JLabelの装飾にMatteBorderを使用し、4辺でそれぞれ異なる線幅の枠を描画します。
image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTPp-xSv1I/AAAAAAAAAeU/K5lHH6YMz_E/s800/MatteBorder.png
---
* 概要 [#j81b32c2]
* 概要 [#summary]
`JLabel`の装飾に`MatteBorder`を使用し、`4`辺でそれぞれ異なる線幅の枠を描画します。

#download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTPp-xSv1I/AAAAAAAAAeU/K5lHH6YMz_E/s800/MatteBorder.png)

* サンプルコード [#a1801918]
* サンプルコード [#sourcecode]
#code(link){{
Border outside = BorderFactory.createMatteBorder(0, 10, 1, 0, Color.GREEN);
Border inside  = BorderFactory.createEmptyBorder(0, 5, 0, 0);
label.setBorder(BorderFactory.createCompoundBorder(outside, inside));
}}

* 解説 [#uc67693e]
* 解説 [#explanation]
`MatteBorder`は、`4`辺それぞれに異なる幅の直線を描画することができます。上記のサンプルでは、左と下のみ枠を描いてタイトル風のラベルを作成しています。

アイコンをタイル状に描画することもできるので、[[JComboBoxにアイコンを表示>Swing/IconComboBox]]のような使い方をする場合もあります。
`Icon`をタイル状に描画することもできるので、[[JComboBoxにアイコンを表示>Swing/IconComboBox]]のような使い方をすることもできます。

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

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