Exemple #1
52
 /**
  * Show the given message in a dialog box or independent window, depending on whether the source
  * component is contained in a Frame or not.
  *
  * @param c The Controller that calls this method, or null if it is not called by a Controller.
  *     (The Controller, if any, will be notified when the error message is cleared.)
  * @param message The message to display.
  */
 public void setErrorMessage(Controller c, String message) {
   if (popup != null) clearErrorMessage();
   if (message == null) return;
   errorSource = c;
   errorMessage = message;
   Component parent = source;
   while (parent != null && !(parent instanceof Frame)) parent = parent.getParent();
   if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog
   else popup = new Frame("Error Message"); // independent window
   popup.setBackground(Color.white);
   popup.add(new MC(message), BorderLayout.CENTER);
   Panel buttonBar = new Panel();
   buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
   Button OK = new Button("    OK    ");
   OK.addActionListener(this);
   buttonBar.add(OK);
   popup.add(buttonBar, BorderLayout.SOUTH);
   popup.pack();
   if (parent == null) popup.setLocation(100, 80);
   else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30);
   popup.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           popup.dispose();
         }
       });
   popup.show(); // make the dialog visible.
 }
 private void addListener(final Window container) {
   container.addWindowFocusListener(
       new WindowAdapter() {
         public void windowLostFocus(WindowEvent evt) {
           container.setVisible(false);
         }
       });
   container.pack();
 }
 public static Window setSize(JComponent content, final Dimension size) {
   final Window popupWindow = SwingUtilities.windowForComponent(content);
   final Point location = popupWindow.getLocation();
   popupWindow.setLocation(location.x, location.y);
   Insets insets = content.getInsets();
   if (insets != null) {
     size.width += insets.left + insets.right;
     size.height += insets.top + insets.bottom;
   }
   content.setPreferredSize(size);
   popupWindow.pack();
   return popupWindow;
 }
Exemple #4
0
 /*
 	This could live in the desktop script.
 	However we'd like to get it on the screen as quickly as possible.
 */
 public static void startSplashScreen() {
   int width = 275, height = 148;
   Window win = new Window(new Frame());
   win.pack();
   BshCanvas can = new BshCanvas();
   can.setSize(width, height); // why is this necessary?
   Toolkit tk = Toolkit.getDefaultToolkit();
   Dimension dim = tk.getScreenSize();
   win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height);
   win.add("Center", can);
   Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif"));
   MediaTracker mt = new MediaTracker(can);
   mt.addImage(img, 0);
   try {
     mt.waitForAll();
   } catch (Exception e) {
   }
   Graphics gr = can.getBufferedGraphics();
   gr.drawImage(img, 0, 0, can);
   win.setVisible(true);
   win.toFront();
   splashScreen = win;
 }
  public void pack() {
    final Window window = SwingUtilities.getWindowAncestor(myContent);

    window.pack();
  }