pack() method not generated

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

pack() method not generated

Postby martinn » Tue Feb 19, 2008 5:52 pm

We just purchased WindowBuilder 6.5.0 - and I installed it under Eclipse 3.3.1. When using the wizard to generate a JFrame, I do not see it generate a call to 'pack()' for the JFrame. This causes the JFrame to not display the components that are added to it. Only after manually adding 'pack()' in the constructor, do I get to see all the components. I'm running Eclipse 3.3.1 on Ubunty 7.10.

The setup of the basic app is pretty simple - a JFrame, Menu Bar, single cascading menu (File), and single item (Exit).

Anyone have any idea why 'pack()' is not being generated, being that without it the code does not display all the GUI components? Thanks!

Martin
martinn
 
Posts: 1
Joined: Tue Feb 19, 2008 5:48 pm

Re: pack() method not generated

Postby Konstantin.Scheglov » Tue Feb 19, 2008 11:17 pm

JFrame wizard adds setBounds() invocation, so JFrame works even without pack().
See screen shot in attachment.
Here is source:

Code: Select all
package test;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class JFrame_1 extends JFrame {
   /**
    * Launch the application
    * @param args
    */
   public static void main(String args[]) {
      try {
         JFrame_1 frame = new JFrame_1();
         frame.setVisible(true);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   /**
    * Create the frame
    */
   public JFrame_1() {
      super();
      setBounds(100, 100, 500, 375);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      {
         final JMenuBar menuBar = new JMenuBar();
         setJMenuBar(menuBar);
         {
            final JMenu fileMenu = new JMenu();
            fileMenu.setText("File");
            menuBar.add(fileMenu);
            {
               final JMenuItem newItemMenuItem = new JMenuItem();
               newItemMenuItem.setText("Exit");
               fileMenu.add(newItemMenuItem);
            }
         }
      }
   }
}
Attachments
Screenshot - 20.02.2008 , 10_14_44.png
JFrame_1 screen shot
Screenshot - 20.02.2008 , 10_14_44.png (6.32 KiB) Viewed 563 times
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest