Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4112308

Adding Menu Bar causes window to grow inordinatately

XMLWordPrintable

    • 1.1.6
    • x86
    • windows_nt
    • Verified


        Compile and run the following files. Press the button(which adds a menubar).
        On NT, the window is resized much larger than necessary and its origin is moved.

        /*
            Form1.java

            NOTE: This file is a generated file.
                  Do not modify it by hand!
        */
        import java.awt.Font;
        import java.awt.FontMetrics;
        import java.awt.Rectangle;
        import java.awt.Insets;
        import java.lang.Math;
        import java.lang.String;

        // custom imports for Form1
        // add your custom import statements here


        class Form1 extends java.awt.Frame implements java.awt.event.WindowListener, java.awt.event.ActionListener
        {
            public Rectangle DURectangle( int x, int y, int w, int h )
            {
                String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
                FontMetrics fm = getFontMetrics( getFont() );
                double fw = ( fm != null ) ? ( fm.stringWidth( alphabet ) / alphabet.length() ) : 0;
                double fh = ( fm != null ) ? ( fm.getHeight() / 2.0 ) : 0.0;

                return new Rectangle( (int) Math.round( ( (double)fw * (double)x ) / 4.0 ),
                                      (int) Math.round( ( (double)fh * (double)y ) / 4.0 ),
                                      (int) Math.round( ( (double)fw * (double)w ) / 4.0 ),
                                      (int) Math.round( ( (double)fh * (double)h ) / 4.0 ) );
            }

            public void DUPositionComponent( java.awt.Component comp, int x, int y, int w, int h, java.awt.Insets formInsets )
            {
                Rectangle rect = DURectangle( x, y, w, h );
                if( formInsets != null ) {
                     rect.x += formInsets.left;
                     rect.y += formInsets.top;
                }
                java.awt.Dimension minSize = comp.getMinimumSize();
                if( rect.width < minSize.width ) {
                    rect.width = minSize.width;
                }
                if( rect.height < minSize.height ) {
                    rect.height = minSize.height;
                }
                comp.setBounds( rect );
            }

            public void setMainForm( boolean isMainForm )
            {
                __mainForm = isMainForm;
            }
            public boolean isMainForm()
            {
                return __mainForm;
            }
            public boolean create() throws java.lang.Exception
            {
                setResizable(true);

                java.awt.Container contentPane = getContentPane();
                Font defaultFont = new Font( "Dialog", Font.PLAIN, 12 );
                setFont( defaultFont );

                boolean retval = true;
                addNotify();
                Insets formInsets = contentPane.getInsets();
                contentPane.setBackground( java.awt.Color.lightGray );
                contentPane.setForeground( java.awt.Color.black );

                contentPane.setLayout( null );
                contentPane.add(lb_1);
                contentPane.add(label_1);
                contentPane.add(cb_1);
                DUPositionComponent( this, 8, 97, 393, 230, null );
                addWindowListener(this);

                DUPositionComponent( lb_1, 10, 120, 370, 80, formInsets );
                lb_1.setFont( defaultFont );
                lb_1.setBackground( java.awt.Color.white );
                lb_1.setForeground( java.awt.Color.black );
                lb_1.setEnabled(true);
                lb_1.setVisible(true);


                DUPositionComponent( label_1, 10, 100, 370, 15, formInsets );
                label_1.setText( "The bottom of this list box should be aligned at the bottom of the form." );
                label_1.setAlignment(java.awt.Label.LEFT);
                label_1.setFont( defaultFont );
                label_1.setBackground( java.awt.Color.lightGray );
                label_1.setForeground( java.awt.Color.black );
                label_1.setEnabled(true);
                label_1.setVisible(true);


                cb_1.addActionListener(this);
                DUPositionComponent( cb_1, 170, 35, 40, 14, formInsets );
                cb_1.setFont( defaultFont );
                cb_1.setBackground( java.awt.Color.lightGray );
                cb_1.setForeground( java.awt.Color.black );
                cb_1.setEnabled(true);
                cb_1.setVisible(true);



                setVisible(true);
                return retval;
            }

            public synchronized boolean destroy()
            {
                if( (java.awt.Container)this instanceof java.awt.Window ) {
                    ((java.awt.Window)(java.awt.Container)this).dispose();
                } else {
                    removeNotify();
                }
                if( isMainForm() ) {
                    System.gc();
                    System.runFinalization();
                    System.exit(0);
                }
                return true;
            }


            public boolean defaultHandleEvent(java.awt.Event event)
            {
                return false;
            }
            public void defaultProcessEvent(java.awt.AWTEvent event)
            {
                super.processEvent(event);
            }

            public void windowClosed( java.awt.event.WindowEvent event )
            {
            }
            public void windowOpened( java.awt.event.WindowEvent event )
            {
            }
            public void windowClosing( java.awt.event.WindowEvent event )
            {
                Object eventTarget = event.getSource();
                if( eventTarget == this ) {
                    Form1_windowClosing( event );
                } else {
                    unhandledEvent( "java.awt.event.WindowListener", "windowClosing", event );
                }
            }
            public void windowIconified( java.awt.event.WindowEvent event )
            {
            }
            public void windowActivated( java.awt.event.WindowEvent event )
            {
            }
            public void windowDeiconified( java.awt.event.WindowEvent event )
            {
            }
            public void windowDeactivated( java.awt.event.WindowEvent event )
            {
            }

            public void actionPerformed( java.awt.event.ActionEvent event )
            {
                Object eventTarget = event.getSource();
                if( eventTarget == cb_1 ) {
                    cb_1_actionPerformed( event );
                } else {
                    unhandledEvent( "java.awt.event.ActionListener", "actionPerformed", event );
                }
            }
            public Form1()
            {
                super();
            }
            public void processEvent(java.awt.AWTEvent event)
            {

                defaultProcessEvent(event);
            }
            public void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
            {

            }
            public java.awt.Container getContentPane()
            {
                return this;
            }
            public boolean Form1_windowClosing(java.awt.event.WindowEvent event)
            {

                setVisible(false);
                destroy();
                return false;
            }
            public void cb_1_actionPerformed( java.awt.event.ActionEvent event )
            {
                
                menu_1_Item0.setLabel("Item0");
                menu_1.add(menu_1_Item0);
                menu_1_Item1.setLabel("Item1");
                menu_1_Item0.add(menu_1_Item1);
                menu_1_Item2.setLabel("Item2");
                menu_1_Item0.add(menu_1_Item2);
                menu_1_Item3.setLabel("Item3");
                menu_1.add(menu_1_Item3);
                menu_1_Item5.setLabel("Item5");
                menu_1_Item3.add(menu_1_Item5);
                menu_1_Item6.setLabel("Item6");
                menu_1_Item3.add(menu_1_Item6);
                menu_1_Item4.setLabel("Item4");
                menu_1.add(menu_1_Item4);
                menu_1_Item7.setLabel("Item7");
                menu_1_Item4.add(menu_1_Item7);
                menu_1_Item8.setLabel("Item8");
                menu_1_Item4.add(menu_1_Item8);
                setMenuBar( menu_1 );

                
            }
            /****************************************
             * data members
             ****************************************/

            boolean __mainForm = false;

            private java.awt.MenuBar menu_1 = new java.awt.MenuBar();
            private java.awt.Menu menu_1_Item0 = new java.awt.Menu("");
            private java.awt.MenuItem menu_1_Item1 = new java.awt.MenuItem("");
            private java.awt.MenuItem menu_1_Item2 = new java.awt.MenuItem("");
            private java.awt.Menu menu_1_Item3 = new java.awt.Menu("");
            private java.awt.MenuItem menu_1_Item5 = new java.awt.MenuItem("");
            private java.awt.MenuItem menu_1_Item6 = new java.awt.MenuItem("");
            private java.awt.Menu menu_1_Item4 = new java.awt.Menu("");
            private java.awt.MenuItem menu_1_Item7 = new java.awt.MenuItem("");
            private java.awt.MenuItem menu_1_Item8 = new java.awt.MenuItem("");
            private java.awt.List lb_1 = new java.awt.List();
            private java.awt.Label label_1 = new java.awt.Label();
            private java.awt.Button cb_1 = new java.awt.Button();

            // add your data members here
        }

              dmendenhsunw David Mendenhall (Inactive)
              tonywyant Tony Wyant (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: