Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Customizing MessageBox(Adding custom components to system MessageBox)
Customizing MessageBox [message #548058] Tue, 20 July 2010 14:34 Go to next message
Albert Pikus is currently offline Albert PikusFriend
Messages: 70
Registered: October 2009
Member
Hi, everybody,

I wonder if it is possible to add custom controls to MessageBox. Although I subclassed MessageBox class, there seem to be no benefit from doing so.

What I would like to achieve is to create a standard message box, with appropriate style bits (e.g. SWT.ICON_INFORMATION | SWT.YES | SW.NO) and a custom control (e.g. a Button with style SWT.CHECK) between the dialog message and YES and NO buttons.

I also looked at jFace Dialogs, but these don't provide the standard appearance (at least not on Windows 7, where system dialogs have a darker gray panel on the lower side of the dialog).

Is this possible to achieve, or do I have to fake it by extending Dialog class and then put the desired system icon on some approximately correct position, by calling
Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION);
?


Any advice is greatly appreciated, best regards,

Albert


Re: Customizing MessageBox [message #548247 is a reply to message #548058] Wed, 21 July 2010 09:06 Go to previous messageGo to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
Hi,

for this use case i would suggest you to subclass IconAndMessageDialog, heres an example from my source:

public class ErrorQuestionMessageDialog extends IconAndMessageDialog
{
    public ErrorQuestionMessageDialog(final Shell parent)
    {
        super(parent);
    }

    @Override
    protected final void configureShell(final Shell newShell)
    {
        super.configureShell(newShell);
        newShell.setText(MainMessages.ERROR_QUESTION_DIALOG_TITLE);
    }

    public final void setMessage(final String message)
    {
        this.message = message;
    }

    @Override
    protected final Control createDialogArea(final Composite parent)
    {
        createMessageArea(parent);
        final Composite composite = new Composite(parent, SWT.NONE);
        final GridData data = new GridData(GridData.FILL_BOTH);
        data.horizontalSpan = 2;
        composite.setLayoutData(data);
        composite.setLayout(new FillLayout());
        return composite;
    }

    @Override
    protected final void createButtonsForButtonBar(final Composite parent)
    {
        createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
        createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
    }

    @Override
    protected final void buttonPressed(final int buttonId)
    {
        setReturnCode(buttonId);
        close();
    }

    @Override
    protected final Image getImage()
    {
        return getErrorImage();
    }
}


Thats a dialog, with the Error Icon and two buttons (Yes, No).
Re: Customizing MessageBox [message #548288 is a reply to message #548247] Wed, 21 July 2010 11:31 Go to previous message
Albert Pikus is currently offline Albert PikusFriend
Messages: 70
Registered: October 2009
Member
Hi,

first I want to thank you for your quick answer.

I tried your suggestion, but this dialog doesn't look like SWT's MessageBox does. The problem is that all dialogs in my application are of MessageBox class and (on Windows 7 at least) look like this:

http://img29.imageshack.us/img29/4917/swtstandarddialog.png

which is pretty much close to native Windows 7 dialog look:

http://img716.imageshack.us/img716/35/windows7standard.png

On the other hand, dialog you suggested looks like this (and for that matter, Eclipse dialogs too) :

http://img37.imageshack.us/img37/3098/jfaceerrordialog.png

Although standard SWT org.eclipse.swt.widgets.MessageBox doesn't look perfectly native on Windows 7, it's close enough, while Eclipse dialogs don't look really native. This isn't the biggest issue at all (perhaps I could live with not perfectly native looking dialogs in my application), but the inconsistent look between SWT dialogs which I'm already using and those provided by jFace.


Best regards,

Albert

[Updated on: Wed, 21 July 2010 11:33]

Report message to a moderator

Previous Topic:How to get VerifyEvent properties: keyCode and start/end at same time?
Next Topic:Opening Excel using SWT Ole mechanism
Goto Forum:
  


Current Time: Tue Mar 19 04:10:12 GMT 2024

Powered by FUDForum. Page generated in 0.02689 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top