• 追加された行はこの色です。
  • 削除された行はこの色です。
#navi(../)
*SystemColorの使用 [#u69460d3]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2003-09-25~
更新日:&lastmod;
---
category: swing
folder: SystemColor
title: SystemColorの使用
tags: [SystemColor]
author: aterai
pubdate: 2003-10-20
description: Swingコンポーネントの色をSystemColorクラスから取得します。
image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTUESCOFBI/AAAAAAAAAlc/eXW_0wilSew/s800/SystemColor.png
---
* 概要 [#summary]
`Swing`コンポーネントの色を`SystemColor`クラスから取得します。

#contents
**概要 [#c694128b]
Swingコンポーネントの色をSystemColorクラスから取得します。
#download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTUESCOFBI/AAAAAAAAAlc/eXW_0wilSew/s800/SystemColor.png)

http://terai.xrea.jp/swing/systemcolor/screenshot1.png
http://terai.xrea.jp/swing/systemcolor/screenshot2.png
* サンプルコード [#sourcecode]
#code(link){{
Box box = Box.createVerticalBox();
box.add(makeSystemColorPanel(SystemColor.desktop, "desktop"));
box.add(makeSystemColorPanel(SystemColor.activeCaption, "activeCaption"));
box.add(makeSystemColorPanel(SystemColor.inactiveCaption, "inactiveCaption"));
box.add(makeSystemColorPanel(SystemColor.activeCaptionText, "activeCaptionText"));
box.add(makeSystemColorPanel(SystemColor.inactiveCaptionText, "inactiveCaptionText"));
box.add(makeSystemColorPanel(SystemColor.activeCaptionBorder, "activeCaptionBorder"));
box.add(makeSystemColorPanel(SystemColor.inactiveCaptionBorder, "inactiveCaptionBorder"));
box.add(makeSystemColorPanel(SystemColor.window, "window"));
box.add(makeSystemColorPanel(SystemColor.windowText, "windowText"));
box.add(makeSystemColorPanel(SystemColor.menu, "menu"));
box.add(makeSystemColorPanel(SystemColor.menuText, "menuText"));
box.add(makeSystemColorPanel(SystemColor.text, "text"));
box.add(makeSystemColorPanel(SystemColor.textHighlight, "textHighlight"));
box.add(makeSystemColorPanel(SystemColor.textText, "textText"));
box.add(makeSystemColorPanel(SystemColor.textHighlightText, "textHighlightText"));
box.add(makeSystemColorPanel(SystemColor.control, "control"));
box.add(makeSystemColorPanel(SystemColor.controlLtHighlight, "controlLtHighlight"));
box.add(makeSystemColorPanel(SystemColor.controlHighlight, "controlHighlight"));
box.add(makeSystemColorPanel(SystemColor.controlShadow, "controlShadow"));
box.add(makeSystemColorPanel(SystemColor.controlDkShadow, "controlDkShadow"));
box.add(makeSystemColorPanel(SystemColor.controlText, "controlText"));
box.add(makeSystemColorPanel(SystemColor.control, "control"));
box.add(makeSystemColorPanel(SystemColor.scrollbar, "scrollbar"));
box.add(makeSystemColorPanel(SystemColor.info, "info"));
box.add(makeSystemColorPanel(SystemColor.infoText, "infoText"));
}}

**サンプルコード [#d56e9e8d]
//#ref(syscolordemo.jar, 実行ファイル)
//#ref(SystemColorDemo_Src.zip, ソース)
* 解説 [#explanation]
各プラットフォームのデスクトップデザインに対応したシステムカラーは、`SystemColor`クラスの`static`フィールドにまとめて定義されています。例えば`Windows`プラットフォームでデスクトップのカスタマイズでテーマなどを変更すると、この`SystemColor`も動的にその変更に追従します。

 Color color = SystemColor.textHighlightText;
- `LookAndFeel`を変更しても`SystemColor`は変化しない
- `GTKLookAndFeel`がシステムデフォルトになる環境では`SystemColor`を取得不可

//以下は、色見本を表示するためのサンプルプログラムです。
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/SystemColor.html SystemColor (Java Platform SE 8)]
- [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/Color.html#getColor-java.lang.String- Color#getColor(...) (Java Platform SE 8)]
// - [http://www.asahi-net.or.jp/~dp8t-asm/java/tips/SystemColor.html システムカラー]

-[[サンプルを起動>http://terai.xrea.jp/swing/systemcolor/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/systemcolor/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/systemcolor/src.zip]]

**解説 [#l578b2c0]
SystemColorを使うと、Windowsなどのディスクトップデザインの配色に対応した色を取得することができます。

**参考リンク [#rcd6ac16]
-[[システムカラー>http://www.asahi-net.or.jp/~dp8t-asm/java/tips/SystemColor.html]]

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