Message Box

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 13:32, 22 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Message boxes contain a defined message and title that may be combined with predefined icons and buttons. Again the central instance to create a Message box is the service It serves as a factory that exports the interface Its method createMessageBox() allows the creation of message boxes in various defined facets.

  • The first parameter of createMessageBox() denotes the peer of the parent window. In analogy to all Apache OpenOffice windows the peer of the window parent must be conveyed.
  • The second parameter aPosSize may be empty (but not null).
  • The third parameter aType describes the special usecase of the message box. The interface description lists a bunch of defined strings like "errorbox" or "querybox". The message box type is than differentiated by its contained icon.
  • Depending on the use case, different combinations of buttons in the message box are possible and reflected by a value of the constants group This is the fourth parameter aButtons.
  • The last two parameters reflect the title (aTitle) and the message (aMessage) of the message box.

This example creates and executes a message box.

  /** shows an error messagebox
   * @param _xParentWindowPeer the windowpeer of the parent window
   * @param _sTitle the title of the messagebox
   * @param _sMessage the message of the messagebox
  public void showErrorMessageBox(XWindowPeer _xParentWindowPeer, String _sTitle, String _sMessage){
  XComponent xComponent = null; 
  try {
      Object oToolkit = m_xMCF.createInstanceWithContext("", m_xContext);
      XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit);
      // rectangle may be empty if position is in the center of the parent peer
      Rectangle aRectangle = new Rectangle();
      XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xParentWindowPeer, aRectangle, "errorbox",, _sTitle, _sMessage);
      xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox);
      if (xMessageBox != null){
          short nResult = xMessageBox.execute();
  } catch ( ex) {
      //make sure always to dispose the component and free the memory!
      if (xComponent != null){
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages