weblaf icon indicating copy to clipboard operation
weblaf copied to clipboard

Enabling JOptionPane window decoration separately

Open iamchathu opened this issue 10 years ago • 6 comments

When i set

WebLookAndFeel.setDecorateDialogs(true);

It affects all my dilaogs.I only need that on Joptionpane dialogs.The Dialogs created by me has to be DecorateDialog setting to be false.

How to achieve this?

iamchathu avatar May 19 '15 05:05 iamchathu

Unfortunately there is no separate option for JOptionPane or WebOptionPane since Swing basically doesn't have one by default. But I might be able to add it later on.

Still, there is a simple workaround - you can set "decorate dialogs" option to true before creating any JOptionPane or WebOptionPane and switch it back to false after. That should do the trick.

Here is a small example:

public class DialogDecorationExample
{
    public static void main ( String[] args )
    {
        WebLookAndFeel.install ();

        final TestFrame frame = TestFrame.show ( new WebLabel ( "Test" ), 50 );

        WebLookAndFeel.setDecorateDialogs ( true );
        JOptionPane.showMessageDialog ( frame, "Sample message" );
        WebLookAndFeel.setDecorateDialogs ( false );
    }
}

Option "decorate dialogs" is queued each time some dialog instance is created. So you are free to change it in runtime if you want to.

mgarin avatar May 19 '15 12:05 mgarin

Is the any way to change WebOptionpane or JOptionPane 's Font and Font Size?

iamchathu avatar May 19 '15 19:05 iamchathu

You can override those globally in Swing defaults:

public class Test
{
    public static void main ( final String[] args )
    {
        WebLookAndFeel.install ();

        UIManager.put ( "OptionPane.messageFont", new Font ( "Arial", Font.ITALIC, 10 ) );
        UIManager.put ( "OptionPane.buttonFont", new Font ( "Arial", Font.BOLD, 20 ) );

        JOptionPane.showMessageDialog ( null, "Info message here with a small font" );
    }
}

Result: image

Though these changes will be applied to all option panes.

mgarin avatar May 20 '15 08:05 mgarin

Thank you. @mgarin :+1:

iamchathu avatar May 20 '15 08:05 iamchathu

Custom decoration of specific frames and dialogs can now be enabled through the styling, but unfortunately JOptionPane creates its own dialogs within private/static methods without any options to affect them in any way, so unfortunately main question of this issue is still not resolved.

mgarin avatar May 13 '16 16:05 mgarin

I might be able to add specific states based on dialog types:

JRootPane.PLAIN_DIALOG
JRootPane.ERROR_DIALOG
JRootPane.QUESTION_DIALOG
JRootPane.WARNING_DIALOG
JRootPane.INFORMATION_DIALOG

But I will postpone that to v1.3.0 release.

mgarin avatar May 13 '16 16:05 mgarin