swingx
Version 2005-08-19

org.jdesktop.swingx
Class JXErrorDialog

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by org.jdesktop.swingx.JXErrorDialog
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class JXErrorDialog
extends JDialog

Common Error Dialog, suitable for representing information about errors and exceptions happened in application. The common usage of the JXErrorDialog is to show collected data about the incident and probably ask customer for a feedback. The data about the incident consists from the title which will be displayed in the dialog header, short description of the problem that will be immediately seen after dialog is became visible, full description of the problem which will be visible after user clicks "Details" button and Throwable that contains stack trace and another usable information that may be displayed in the dialog.

There are two basic ways to use the JXErrorDialog. The first is to call one of the standard static methods for displaying the error dialog. Here is a basic example:


      try {
          //do some work
          //some exception is thrown
      } catch (Exception e) {
          JXErrorDialog.showDialog(this, "Critical Error",
                  "<html><body>Some <b>critical error</b> has occured." +
                  " You may need to restart this application. Message #SC21." +
                  "</body></html>", e);
      }
 

For the vast majority of use cases, the static methods should be sufficient and are recommended. However, for those few use cases requireing customizations, you can create and display a JXErrorDialog manually.

To ask user for feedback extend abstract class ErrorReporter and set your reporter using setReporter method. Report button will be added to the dialog automatically.
See MailErrorReporter documentation for the example of error reporting usage.

For example, to show simple JXErrorDialog call
JXErrorDialog.showDialog(null, "Application Error", "The application encountered the unexpected error, please contact developers")

Internationalization is handled via a resource bundle or via the UIManager bidi orientation (usefull for right to left languages) is determined in the same way as the JOptionPane where the orientation of the parent component is picked. So when showDialog(Component cmp, ...) is invoked the component orientation of the error dialog will match the component orientation of cmp.

See Also:
Serialized Form

Nested Class Summary
 class JXErrorDialog.ReportAction
          Action for report button
 
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JXErrorDialog(Dialog owner)
          Create a new ErrorDialog with the given Dialog as the owner
JXErrorDialog(Frame owner)
          Create a new ErrorDialog with the given Frame as the owner
 
Method Summary
static Icon getDefaultErrorIcon()
           
static ErrorReporter getDefaultErrorReporter()
          Returns the current reporting engine that will be used to report a problem if user clicks on 'Report' button or null if no reporting engine set.
static Icon getDefaultWarningIcon()
           
 Icon getErrorIcon()
          Returns the Icon in use if the IncidentInfo is Level.SEVERE
 ErrorReporter getErrorReporter()
          Returns the error reporter in use with this instance of JXErrorDialog.
 IncidentInfo getIncidentInfo()
          Get curent dialog's IncidentInfo
 Action getReportAction()
           
static ErrorReporter getReporter()
          Deprecated. Use getDefaultErrorReporter instead
 Icon getWarningIcon()
          Returns the Icon in use if the IncidentInfo is not Level.SEVERE
static void setDefaultErrorIcon(Icon icon)
          Set the Icon to use as the default error icon for JXErrorDialog instances.
static void setDefaultErrorReporter(ErrorReporter rep)
          Set reporting engine which will handle error reporting if user clicks 'report' button.
static void setDefaultWarningIcon(Icon icon)
          Set the Icon to use as the default warning icon for JXErrorDialog instances.
 void setErrorIcon(Icon icon)
          Specifies the icon to use if the IncidentInfo is Level.SEVERE
 void setErrorReporter(ErrorReporter rep)
          Sets the ErrorReporter to use with this instance of JXErrorDialog.
 void setIncidentInfo(IncidentInfo info)
          Sets the IncidentInfo for this dialog
 void setReportAction(Action action)
          Specify the Action that will be executed to report an error/warning.
static void setReporter(ErrorReporter rep)
          Deprecated. Use setDefaultErrorReporter instead
 void setWarningIcon(Icon icon)
          Specifies the icon to use if the IncidentInfo is not Level.SEVERE
static void showDialog(Component owner, IncidentInfo info)
          Show the error dialog.
static void showDialog(Component owner, String title, String errorMessage)
          Show the error dialog.
static void showDialog(Component owner, String title, String errorMessage, String details)
          Show the error dialog.
static void showDialog(Component owner, String title, String errorMessage, Throwable e)
          Constructs and shows the error dialog for the given exception.
static void showDialog(Component owner, String title, Throwable e)
          Constructs and shows the error dialog for the given exception.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JXErrorDialog

public JXErrorDialog(Frame owner)
Create a new ErrorDialog with the given Frame as the owner

Parameters:
owner - Owner of this error dialog.

JXErrorDialog

public JXErrorDialog(Dialog owner)
Create a new ErrorDialog with the given Dialog as the owner

Parameters:
owner - Owner of this error dialog.
Method Detail

setIncidentInfo

public void setIncidentInfo(IncidentInfo info)
Sets the IncidentInfo for this dialog

Parameters:
info - IncidentInfo that incorporates all the details about the error

getIncidentInfo

public IncidentInfo getIncidentInfo()
Get curent dialog's IncidentInfo

Returns:
IncidentInfo assigned to this dialog

setErrorReporter

public void setErrorReporter(ErrorReporter rep)
Sets the ErrorReporter to use with this instance of JXErrorDialog. If not specified, the default error reporter is used (as specified by the setDefaultErrorReporter() static method).

Parameters:
rep - if null, the default error reporter is used

getErrorReporter

public ErrorReporter getErrorReporter()
Returns the error reporter in use with this instance of JXErrorDialog. If not specified, the default error reporter is returned

Returns:
the ErrorReporter in use. May be null

setErrorIcon

public void setErrorIcon(Icon icon)
Specifies the icon to use if the IncidentInfo is Level.SEVERE

Parameters:
icon - the Icon to use. If null, the default error icon will be used

getErrorIcon

public Icon getErrorIcon()
Returns the Icon in use if the IncidentInfo is Level.SEVERE

Returns:
the Icon

setWarningIcon

public void setWarningIcon(Icon icon)
Specifies the icon to use if the IncidentInfo is not Level.SEVERE

Parameters:
icon - the Icon to use. If null, the default warning icon will be used

getWarningIcon

public Icon getWarningIcon()
Returns the Icon in use if the IncidentInfo is not Level.SEVERE

Returns:
the Icon

setReportAction

public void setReportAction(Action action)
Specify the Action that will be executed to report an error/warning. If null, then a default ReportAction will be used.

Parameters:
action - The Action to execute if the user attempts to report a problem

getReportAction

public Action getReportAction()
Returns:
the Action that is executed if the user attempts to report a problem

showDialog

public static void showDialog(Component owner,
                              String title,
                              Throwable e)
Constructs and shows the error dialog for the given exception. The exceptions message will be the errorMessage, and the stacktrace will be the details.

Parameters:
owner - Owner of this error dialog. Determines the Window in which the dialog is displayed; if the owner has no Window, a default Frame is used
title - Title of the error dialog
e - Exception that contains information about the error cause and stack trace

showDialog

public static void showDialog(Component owner,
                              String title,
                              String errorMessage,
                              Throwable e)
Constructs and shows the error dialog for the given exception. The exceptions message is specified, and the stacktrace will be the details.

Parameters:
owner - Owner of this error dialog. Determines the Window in which the dialog is displayed; if the owner has no Window, a default Frame is used
title - Title of the error dialog
errorMessage - Message for the error dialog
e - Exception that contains information about the error cause and stack trace

showDialog

public static void showDialog(Component owner,
                              String title,
                              String errorMessage,
                              String details)
Show the error dialog.

Parameters:
owner - Owner of this error dialog. Determines the Window in which the dialog is displayed; if the owner has no Window, a default Frame is used
title - Title of the error dialog
errorMessage - Message for the error dialog
details - Details to be shown in the detail section of the dialog. This can be null if you do not want to display the details section of the dialog.

showDialog

public static void showDialog(Component owner,
                              String title,
                              String errorMessage)
Show the error dialog.

Parameters:
owner - Owner of this error dialog. Determines the Window in which the dialog is displayed; if the owner has no Window, a default Frame is used
title - Title of the error dialog
errorMessage - Message for the error dialog

showDialog

public static void showDialog(Component owner,
                              IncidentInfo info)
Show the error dialog.

Parameters:
owner - Owner of this error dialog. Determines the Window in which the dialog is displayed; if the owner has no Window, a default Frame is used
info - IncidentInfo that incorporates all the information about the error

getReporter

public static ErrorReporter getReporter()
Deprecated. Use getDefaultErrorReporter instead

Returns the current reporting engine that will be used to report a problem if user clicks on 'Report' button or null if no reporting engine set.

Returns:
reporting engine

setReporter

public static void setReporter(ErrorReporter rep)
Deprecated. Use setDefaultErrorReporter instead

Set reporting engine which will handle error reporting if user clicks 'report' button.

Parameters:
rep - ErrorReporter to be used or null to turn reporting facility off.

getDefaultErrorReporter

public static ErrorReporter getDefaultErrorReporter()
Returns the current reporting engine that will be used to report a problem if user clicks on 'Report' button or null if no reporting engine set.

Returns:
reporting engine

setDefaultErrorReporter

public static void setDefaultErrorReporter(ErrorReporter rep)
Set reporting engine which will handle error reporting if user clicks 'report' button.

Parameters:
rep - ErrorReporter to be used or null to turn reporting facility off.

setDefaultErrorIcon

public static void setDefaultErrorIcon(Icon icon)
Set the Icon to use as the default error icon for JXErrorDialog instances. This icon is used whenever the IncidentInfo for a JXErrorDialog has an errorLevel of Level.SEVERE

Parameters:
icon - the Icon to use as the default error icon

getDefaultErrorIcon

public static Icon getDefaultErrorIcon()
Returns:
the default error icon

setDefaultWarningIcon

public static void setDefaultWarningIcon(Icon icon)
Set the Icon to use as the default warning icon for JXErrorDialog instances. This icon is used whenever the IncidentInfo for a JXErrorDialog has an errorLevel that is not Level.SEVERE

Parameters:
icon - the Icon to use as the default warning icon

getDefaultWarningIcon

public static Icon getDefaultWarningIcon()
Returns:
the default warning icon

swingx
Version 2005-08-19