Here you can find the source of decorate(JDialog dialog, int type)
Parameter | Description |
---|---|
dialog | a parameter |
type | one of UIUtil.(POPUP, UTILITY, NORMAL) |
public static void decorate(JDialog dialog, int type)
//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); } } }