Panel クラス
- [内容]
- 他のコンポーネントを貼り付けるために使用されます.Frame や Diaog に貼り付けて,それらのレイアウト設計に使用されます.デフォルトレイアウトは,FlowLayout です.機能的には,Frame や Dialog と似ていますが,境界やタイトル部分を持たず,直接見ることはできません.
- [コンストラクタ]
- public Panel()
- public Panel(LayoutManager layout)
- 指定されたレイアウトマネージャを使用して Panel オブジェクトを生成する.レイアウトマネージャを指定しないと,デフォルトレイアウトマネージャ( FlowLayout )が選択される.
- [主なメソッド]
- public Component add(Component comp) ( Container から継承)
- コンポーネントを付加する
- public Component add(Component comp, int index) ( Container から継承)
- コンポーネントを指定した位置に付加する.index が -1 の場合は最後に付加される.
- public void add(Component comp, Object constraints) ( Container から継承)
- レイアウトマネージャの制約に従って,コンポーネントを付加する
- public void add(Component comp, Object constraints, int index) ( Container から継承)
- レイアウトマネージャの制約に従って,指定された位置にコンポーネントを付加する
- public void add(PopupMenu popup) ( Component から継承)
- ポップアップメニューを付加する
- public void addComponentListener ( ComponentListener l ) ( Component から継承)
- ComponentListener を付加する
- public void addFocusListener ( FocusListener l ) ( Component から継承)
- FocusListener を付加する
- public void addKeyListener ( KeyListener l ) ( Component から継承)
- KeyListener を付加する
- public void addMouseListener ( MouseListener l ) ( Component から継承)
- MouseListener を付加する
- public void addMouseMotionListener ( MouseMotionListener l ) ( Component から継承)
- MouseMotionListener を付加する
- public boolean contains(Point p) ( Component から継承)
- public boolean contains(int x, int y) ( Component から継承)
- コンポーネントが指定された点を含んでいるか否かを返す(参照: Point クラス)
- public Graphics getGraphics() ( Component から継承)
- このコンポーネントのグラフィックスコンテキストを作成する.コンポーネントが現在表示可能でない場合は,null を返す.(参照: TextArea クラス)
- public Insets getInsets() ( Container から継承)
- コンテナの境界のサイズを示す.
- public Container getParent() ( Component から継承)
- このコンポーネントの親を返す
- public void paint(Graphics g) ( Container から継承)
- 描画
- public void remove(MenuComponent m) ( Component から継承)
- 指定されたメニューバーを削除する
- public void remove(Component comp) ( Container から継承)
- 指定されたコンポーネントを取り除く
- public void remove(int index) ( Container から継承)
- index で指定されたコンポーネントを取り除く
- public void removeAll() ( Container から継承)
- すべてのコンポーネントを取り除く
- public void removeComponentListener ( ComponentListener l ) ( Component から継承)
- ComponentListener を取り除く
- public void removeFocusListener ( FocusListener l ) ( Component から継承)
- FocusListener を取り除く
- public void removeKeyListener ( KeyListener l ) ( Component から継承)
- KeyListener を取り除く
- public void removeMouseListener ( MouseListener l ) ( Component から継承)
- MouseListener を取り除く
- public void removeMouseMotionListener ( MouseMotionListener l ) ( Component から継承)
- MouseMotionListener を取り除く
- 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(long tm, int x, int y, int width, int height) ( Component から継承)
- 指定された矩形領域を,tm ミリ秒以内に再描画する
- public void setBackground(Color c) ( Component から継承)
- バックグラウンドカラーを設定する
- public void setBounds(int x, int y, int width, int height) ( Component から継承)
- public void setBounds(Rectangle r) ( Component から継承)
- コンポーネントを動かし,大きさを変える(参照: Rectangle クラス)
- public void setEnabled(boolean b) ( Component から継承)
- コンポーネントを enable,または,disable にする.disable にするとイベントを受け付けなくなる.
- public void setFont(Font f) ( Container から継承)
- コンテナのフォントを設定する
- public void setForeground(Color c) ( Component から継承)
- フォアグラウンドカラーを設定する
- public void setLayout(LayoutManager mgr) ( Container から継承)
- コンテナのレイアウトマネージャを設定する
- public void setLocation(int x, int y) ( Component から継承)
- public void setLocation(Point p) ( Component から継承)
- コンポーネントの位置を設定する(参照: Point クラス)
- public void setName(String name) ( Component から継承)
- コンポーネントの名前を設定する
- public void setSize(int width, int height) ( Component から継承)
- public void setSize(Dimension d) ( Component から継承)
- コンポーネントの大きさを width ( d.width ),height ( d.height ) に設定する( Dimension については,Frame クラスのプログラム例を参照)
- public void setVisible(boolean b) ( Component から継承)
- コンポーネントを表示,非表示にする
- public void validate() ( Container から継承)
- このコンテナおよびすべてのサブコンポーネントを検証し,コンテナが格納しているコンポーネントが追加または変更されたあとで,コンテナがそのサブコンポーネントをもう一度配置できるようにする
- [使用例]
- プログラム例は,簡単な描画の例です.Window を GridLayout により,上下 2 つに分け,下の領域に貼り付けた Panel に描画しています.

- プログラム例は,レイアウトマネージャを使用せずにボタンを貼り付けた例です.

- プログラム例は,コンポーネントを動的に再配置する例です.上のテキストフィールドに数値を入力すると,その数だけのテキストフィールドが下に表示されます.この例は,ScrollPane クラスや TextListener インタフェースの使用方法の例にもなっています.
- [参照]
- Frame, JPanel