JLabel クラス
- [内容]
- 文字列やイメージを表示するためのクラスです
- [主な変数]
- public static final int CENTER ( SwingConstants から継承)
- 中央を示す
- public static final int LEADING ( SwingConstants から継承)
- リーディングエッジを示す
- public static final int LEFT ( SwingConstants から継承)
- 左を示す
- public static final int RIGHT ( SwingConstants から継承)
- 右を示す
- public static final int TRAILING ( SwingConstants から継承)
- トレーリングエッジを示す
- [コンストラクタ]
- public JLabel()
- public JLabel(Icon image)
- public JLabel(Icon image, int horizontalAlignment)
- public JLabel(String text)
- public JLabel(String text, Icon icon, int horizontalAlignment)
- public JLabel(String text, int horizontalAlignment)
- JLabel オブジェクトを生成する.水平方向の位置( horizontalAlignment )は,LEFT,CENTER,RIGHT,LEADING,または,TRAILING から選択する.
- [主なメソッド]
- public void paint(Graphics g) ( JComponent から継承)
- コンポーネントを描画
- public void paintAll(Graphics g) ( Component から継承)
- このコンポーネントおよびそのすべてのサブコンポーネントを描画
- public void paintComponent(Graphics g) ( JComponent から継承)
- コンポーネントを描画
- public void paintComponents(Graphics g) ( Container から継承)
- コンテナ内の各コンポーネントを描画
- public void repaint() ( Component から継承)
- public void repaint(int x, int y, int width, int height) ( Component から継承)
- public void repaint(long tm) ( Component から継承)
- public void repaint(Rectangle r) ( JComponent から継承)
- public void repaint(long tm, int x, int y, int width, int height) ( JComponent から継承)
- 指定された矩形領域を,tm ミリ秒以内に再描画する
- public void setBackground(Color c) ( JComponent から継承)
- バックグラウンドカラーを設定する
- public void setFont(Font f) ( JComponent から継承)
- フォントを設定する
- pu blic void setForeground(Color c) ( JComponent から継承)
- フォアグラウンドカラーを設定する
- public void setHorizontalTextPosition(int textPosition)
- ラベルテキストのイメージに対する水平位置を設定する.LEFT,CENTER,RIGHT,LEADING,または,TRAILING から選択する.
- public void setIcon(Icon icon)
- アイコンを設定する
- public void setIconTextGap(int iconTextGap)
- テキストとアイコンの間隔を設定する
- public void setOpaque(boolean isOpaque) ( JComponent から継承)
- true の場合,コンポーネントはその境界内のすべてのピクセルをペイントする.false の場合は,コンポーネントはピクセルの一部または全部をペイントしないため,その下のピクセルが透けて表示される.JLabel のデフォルト値は false であるため,背景色を設定してもそれが反映されない.反映させるためには,true に再設定する必要がある.
- public void setText(String text)
- テキストを設定する
- public void setVisible(boolean b) ( JComponent から継承)
- コンポーネントを表示,非表示にする
- [使用例]
- プログラム例は,JLabel クラスの各メソッド等の使用例です.上部に文字のラベルが,また,中央には,文字とアイコンを持ったラベルが貼り付けてあります.

- [参照]
- Label