mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

Enabling JOptionPane window decoration separately #281

Open iamchathu opened 9 years ago

iamchathu commented 9 years ago

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?

mgarin commented 9 years ago

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.

iamchathu commented 9 years ago

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

mgarin commented 9 years ago

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.

iamchathu commented 9 years ago

Thank you. @mgarin :+1:

mgarin commented 8 years ago

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 commented 8 years ago

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.