Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/simscomputing/testbed/gui/ErrorDialog.java


1   package com.simscomputing.testbed.gui;
2   
3   import com.simscomputing.swing.SwingUtilities;
4   
5   import java.awt.Container;
6   import java.awt.GridBagConstraints;
7   import java.awt.GridBagLayout;
8   import java.awt.Insets;
9   import java.awt.event.ActionEvent;
10  import java.awt.event.ActionListener;
11  
12  import javax.swing.JButton;
13  import javax.swing.JDialog;
14  import javax.swing.JFrame;
15  import javax.swing.JLabel;
16  import javax.swing.JScrollPane;
17  import javax.swing.JTextPane;
18  import javax.swing.text.BadLocationException;
19  import javax.swing.text.DefaultStyledDocument;
20  
21  /**
22  Shows program information.
23  
24  @author David Sims
25  @version $Revision: 1.1.1.1 $ $Date: 2000/02/21 21:22:35 $
26  */
27  public class ErrorDialog extends JDialog {
28    public ErrorDialog(JFrame parent, String title, String errorMessage) {
29      super(parent, true);
30  
31      setTitle(title);
32  
33      final Container root = getContentPane();
34      root.setLayout(new GridBagLayout());
35      
36      DefaultStyledDocument pd = new DefaultStyledDocument();
37      try {
38        pd.insertString(0, errorMessage, null);
39      } // try
40      catch (BadLocationException e) {
41        // fixme
42      } // catch
43      final JTextPane contents = new JTextPane(pd);
44      contents.setEditable(false);
45      JButton okButton = new JButton("OK");
46      okButton.addActionListener(new ActionListener() {
47        public void actionPerformed(ActionEvent e) {
48          dispose();
49        }
50      });
51  
52      final int INSET = Resources.INSET;
53      final Insets INSETS = new Insets(INSET, INSET, INSET, INSET);
54      root.add(new JScrollPane(contents),
55               new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
56                                      GridBagConstraints.CENTER,
57                                      GridBagConstraints.BOTH,
58                                      INSETS,
59                                      0, 0));
60  
61      root.add(okButton,
62               new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
63                                      GridBagConstraints.CENTER,
64                                      GridBagConstraints.NONE,
65                                      INSETS,
66                                      0, 0));
67  
68      pack();
69      okButton.requestFocus();
70      setSize(400, 300);
71      SwingUtilities.centerOnParent(this, parent);
72  
73      getRootPane().setDefaultButton(okButton);
74  //      pack();
75    } // constructor
76  } // class ErrorDialog