由于客户需要,我在开发中将构造的JFrame和JDialog的L&F(LookAndFeel)设置成Java的Default风格,但是导致了所有的JDialog的最大化、最小化以及关闭的按钮消失,由于无法获得关于AppContext类的源码,因此不知如何解决……望所有达人赐教……
方便的话最好能介绍一下JFrame与JDialog中关于setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)方法的区别。紧急阿~~紧急~~

解决方案 »

  1.   

    import java.awt.*;
    import javax.swing.*;public class Test {
        public static void main(String[] args) {
           try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
           } catch (Exception e) {}        JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            Toolkit.getDefaultToolkit().setDynamicLayout(true);
            System.setProperty("sun.awt.noerasebackground","true");        JFrame frame = new JFrame("Frame");
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
                    frame.getGraphicsConfiguration());
            
            Rectangle maximizeBounds = new Rectangle(
             screenInsets.left, screenInsets.top, 
             screenSize.width - screenInsets.left - screenInsets.right,
             screenSize.height - screenInsets.top - screenInsets.bottom);
            frame.setMaximizedBounds(maximizeBounds);
            
            frame.setSize(800, 600);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);        JDialog dialog = new JDialog(frame, "Dialog", true);
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setSize(200, 200);
            dialog.setLocationRelativeTo(frame);
            dialog.setVisible(true);
        }
    }
      

  2.   

    楼上的仁兄,我可能没说明白,我想要得是
    JDialog.setDefaultLookAndFeelDecorated(true);
    后的JDialog能出现右上角关闭按钮
    你上面的代码终究会有这个问题,你除了使用结束进程,是无法把你的窗口关掉的(当然是在上述模式下)
      

  3.   

    查了一下,这是1.4里的的一个bug, 在1.5里改正了,刚才我用的是1.5,所以没有发现这个问题
    参见
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4820659
    可惜这里面没有给出比较好的Work Around