Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Message dialogs



There are two ways to create simple messages dialogs:
All these methods use internally the DefaultMDIDialogBuilder class.

Using the GUI application

Several GUI application methods allow to add simple message dialogs: In all the cases the messages argument specifies the array of messages which will be shown in the dialog, organized in a vertical grid.

Example

The following example creates a message dialog presenting the width and height of an image:
      public class AnalyzeImageAction extends AbstractMDIAction {
         public AnalyzeImageAction(MDIApplication appli, String name) {
           super(appli, name);
           this.setDescription("Analyze", "Analyze Image");
         }

         @Override
         public void run() throws Exception {
           GUIApplication gui = ((GUIApplication) app);
           BufferedImage image = (BufferedImage) gui.getSelectedProperties().getObject();
           gui.showMessageDialog("Size", MDIDialogBuilder.INFORMATION_MESSAGE, "Width: " + image.getWidth(), "Height: " + image.getHeight());
         }
      }
with the following result:
messageDialog

Using the MDIMessageDialogHelper class

Several static methods of the MDIMessageDialogHelper class allow to add simple message dialogs: As you can see, you don"t need an instance of the GUIApplication to execute these methods[1]
The GUI application instance is provided to this class at the start of the framework
.

This method allows to show message dialogs in the way of the JOptionPane class in the JDK.

Example

The following example creates a message dialog presenting the width and height of an image, using the MDIMessageDialogHelper:
      public class AnalyzeImageAction extends AbstractMDIAction {
         public AnalyzeImageAction(MDIApplication appli, String name) {
           super(appli, name);
           this.setDescription("Analyze", "Analyze Image");
         }

         @Override
         public void run() throws Exception {
           GUIApplication gui = ((GUIApplication) app);
           BufferedImage image = (BufferedImage) gui.getSelectedProperties().getObject();
           MDIMessageDialogHelper.showMessageDialog("Size", MDIDialogBuilder.INFORMATION_MESSAGE, "Width: " + image.getWidth(), "Height: " + image.getHeight());
         }
      }
with the following result:
messageDialog

Notes

  1. ^ The GUI application instance is provided to this class at the start of the framework

See also


Categories: gui | swing

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences