| ■swingコンポーネント->JDialog | ||
| 自作のウインドウを表示します。JFileChooserは書式が決まってますが、JDialogは自作できるのでいろいろと対応させることができます。 | ||
| 
      ※JDialogを使うには。。 JDialogクラスを継承して新しいクラスを作成します。(部品の配置、ボタン機能などを行います。) インスタンス生成は親のプログラム内でJDialogクラスを継承したクラス名で行います。 ただし、JDialogを閉じる時はsetVisible(false)を使うこと。  |     
    ||
              |     
      ⇒ | ![]()  | 
    
| 
       「ダイアログ表示」をクリックすると自作ダイアログが表示されます。  |     
    |||
| 
       |     
    |||
| コンストラクタ | |||
      
  |     
    |||
| メソッド(抜粋) | |||
      
  |     
    |||
| 
       |     
    |||
| JDialogSample.java | |||
| import java.awt.*; | |||
| import java.awt.event.*; | |||
| import javax.swing.*; | |||
| public class JDialogSample extends Frame { | |||
| Container contentPane; | |||
| JButton btn = new JButton("ダイアログ表示"); | ← @インスタンス生成 | ||
| public JDialogSample() { | |||
| super(JDialogSample); | |||
| addWindowAdapter(new WindowListener() { | |||
| public void windowClosing(WindowEvent e) { | |||
| System.exit(0); | |||
| } | |||
| }); | |||
| contentPane = getContentPane(); | |||
| contentPane.setLayout(new BorderLayout()); | |||
| contentPane.add(BorderLayout.CENTER,btn); | |||
| btn.addActionListener(this); | |||
| pack(); | |||
| setLocation(150,150); | |||
| setVisible(true); | |||
| } | |||
| public void actionPerformed(ActionEvent e) { | |||
| MyDialog md = new MyDialog(this); | |||
| } | |||
| public static void main(String[] args) { | |||
| JDialogSample myClass = new JDialogSample(); | |||
| } | |||
| } | |||
| class MyDialog extends JDialog implements ActionListener { | |||
| Container contentPane; | |||
| JDialogSample parent; | |||
| JLabel lbl = new JLabel("ダイアログです"); | |||
| JButton btn = new JButton("閉じる"); | |||
| public MyDialog(JDialogSample parent) { | |||
| super(parent,"ダイアログ",true); | |||
| contentPane = getContentPane(); | |||
| contentPane.setLayout(new BorderLayout()); | |||
| contentPane.add(BorderLayout.CENTER,lbl); | |||
| contentPane.add(BorderLayout.EAST,btn); | |||
| btn.addActionListener(this); | |||
| setSize(200,100); | |||
| setLocation(200,200); | |||
| setVisible(true); | |||
| } | |||
| public void actionPerformed(ActionEvent e) { | |||
| setVisible(false); | |||
| } | |||
| } | |||
| @JTextAreaのインスタンスを生成 インスタンスを生成しています。  |     
    |||
| ※マウスの範囲選択や、ctrl+cでのコピー、ctrl+vでの貼り付けはできます。 | |||
| もどる | |||