Java JDialog decorate(JDialog dialog, int type)

Here you can find the source of decorate(JDialog dialog, int type)

Description

Sets the look of the given dialog.

License

LGPL

Parameter

Parameter Description
dialog a parameter
type one of UIUtil.(POPUP, UTILITY, NORMAL)

Declaration

public static void decorate(JDialog dialog, int type) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import javax.swing.*;

import java.awt.*;

import java.lang.reflect.Method;

public class Main {
    public final static int POPUP = 0;
    public final static int UTILITY = 1;
    public final static int NORMAL = 2;

    /**/* www.  j  av a 2  s  . c om*/
     * Sets the look of the given dialog. Works only on Java 7+, but does not
     * crash on Java 6-.
     *
     * @param dialog
     * @param type one of UIUtil.(POPUP, UTILITY, NORMAL)
     */
    public static void decorate(JDialog dialog, int type) {
        try {
            Class windowType = Class.forName("java.awt.Window$Type");
            Method setType = Window.class.getDeclaredMethod("setType", windowType);
            switch (type) {
            case POPUP:
                setType.invoke(dialog,
                        Enum.valueOf((Class<Enum>) windowType.getDeclaredField("POPUP").getType(), "POPUP"));
                break;
            case UTILITY:
                setType.invoke(dialog,
                        Enum.valueOf((Class<Enum>) windowType.getDeclaredField("UTILITY").getType(), "UTILITY"));
                break;
            case NORMAL:
                setType.invoke(dialog,
                        Enum.valueOf((Class<Enum>) windowType.getDeclaredField("NORMAL").getType(), "NORMAL"));
                break;
            }

        } catch (Exception e) {
            // This ClassNotFound occurs if the user doesn't have Java 7 installed.
            // We can still create a utility-looking window, though.
            // Just doesn't look as nice.
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
        }
    }
}

Related

  1. cascadeDialog(JDialog dialog, JDialog parent)
  2. chooseFile(final JDialog dialog, final String title)
  3. closeDialog(final JDialog dialog)
  4. commonFileDialog(JDialog parent, boolean save)
  5. configureCancelForDialog(final JDialog dialog, JButton cancelButton)
  6. displayInDialog(JComponent comp, JDialog result)
  7. disposeOnClose(javax.swing.JDialog d)
  8. enableAllComponents(final boolean enable, final JDialog parent)
  9. enableAllComponentsExcept(final boolean enable, final JDialog parent, final Component... components)