public class desktopapplication2ShowNewData extends javax.swing.JDialog {
    /** Creates new form desktopapplication2ShowNewData */
    public desktopapplication2ShowNewData(java.awt.Frame parent) {
        super(parent);
        initComponents();
    }
}
这是我用netbeans创建的一个新窗口,请问我要如何设置他的大小呢?我在 构造方法里加了 this.setsize(100,100);
没有任何效果。

解决方案 »

  1.   

    this.setSize(100,100);是没有问题的
    如果没有效果,可能是你在其它地方又调用的setSize,或者pack方法
      

  2.   


    是 的,我发现在系统自动生成的 private void initComponents()方法最后调用了pack();这个方法,可是我没有办法去掉pack();这个方法,我又该如何设置窗口大小呢?
      

  3.   


        private void initComponents() {        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setName("Form"); // NOI18N        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 639, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );        pack();
        }
    这个是系统自动生成的方法
      

  4.   

    那你就在调用initComponents后,  再setSize吧
      

  5.   


        public desktopapplication2ShowNewData(java.awt.Frame parent) {
            super(parent);
            initComponents();
            this.setSize(100, 100);
        }这样依然没有效果,像这样写,this.setSize(100, 100);
    这个方法貌似不会执行。
      

  6.   

    那你先这样, 看setSize()有用吗?    public desktopapplication2ShowNewData(java.awt.Frame parent) {
            super(parent);
            //initComponents();
            this.setSize(100, 100);
        }
      

  7.   

    先确认是否initComponents导致的问题, 看看是否还有其它地方也对大小产生了影响
      

  8.   


    当我创建一个窗口类时,initComponents(); 这个方法就自动生成了,我添加组件时,系统会自动在这个方法里添加相应的代码。所以这个方法基本是不能重写的。
      

  9.   


    那么,应该是其它地方调用了setSize或pack方法,  找找看!
      

  10.   

    那么,应该是其它地方调用了setSize或pack方法, 找找看!
    没有了, 这 个类里就这一个方法initComponents();
      

  11.   

    我认为应该开一个NetBeans的技术论坛···
      

  12.   


    public class desktopapplication2JGTBox extends javax.swing.JDialog {    /** Creates new form desktopapplication2JGTBox */
        public desktopapplication2JGTBox(java.awt.Frame parent) {
            super(parent);
            initComponents();
        }    /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setName("Form"); // NOI18N        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 639, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );        pack();
        }// </editor-fold>                            // Variables declaration - do not modify                     
        // End of variables declaration                   }这就是新建的一个完整的类。
      

  13.   

    找不到有其他地方调用setSize或pack方法了