Gridbaglayout Design Page Nested Panel shows large gaps

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

Gridbaglayout Design Page Nested Panel shows large gaps

Postby chrisR » Sun Aug 16, 2009 9:59 pm

Here is an example:
A Panel with an Etched Border on a Panel with GridBagLayout.
Code: Select all
public PanelWithBorder() {

      initialize();
   }
   private void initialize() {
      GridBagLayout gridBagLayout = new GridBagLayout();
      gridBagLayout.columnWidths = new int[]{0, 0};
      gridBagLayout.rowHeights = new int[]{0, 0};
      gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
      gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
      setLayout(gridBagLayout);
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.fill = GridBagConstraints.BOTH;
      gbc.gridx = 0;
      gbc.gridy = 0;
      add(getPnl(), gbc);
   }
   protected JPanel getPnl() {
      if (pnl == null) {
         pnl = new JPanel();
         pnl.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
         pnl.setName("pnl");
      }
      return pnl;
   }

I put this Panel on the contentpane of a JFrame with Gridbaglayout.
Code: Select all
   /**
    * Create the frame.
    */
   public FrameForPanelWithBorder() {
      initialize();
   }
   private void initialize() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 450, 300);
      contentPane = new JPanel();
      GridBagLayout gridBagLayout = new GridBagLayout();
      gridBagLayout.columnWidths = new int[]{0, 0};
      gridBagLayout.rowHeights = new int[]{0, 0};
      gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
      gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
      contentPane.setLayout(gridBagLayout);
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.fill = GridBagConstraints.BOTH;
      gbc.gridx = 0;
      gbc.gridy = 0;
      contentPane.add(getPanelWithBorder(), gbc);
   }

   protected PanelWithBorder getPanelWithBorder() {
      if (panelWithBorder == null) {
         panelWithBorder = new PanelWithBorder();
         panelWithBorder.setName("panelWithBorder");
      }
      return panelWithBorder;
   }

The design page shows the border of the panel, however there
is a gap to the right and the bottom.
If I start the Frame as an application there is no gap. That's O.K.
If I remove the dummy column and row of the "PanelWithBorder" the design page shows no gap.
Code: Select all
      //      gridBagLayout.columnWidths = new int[]{0, 0};
      //      gridBagLayout.rowHeights = new int[]{0, 0};
      //      gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
      //      gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
      gridBagLayout.columnWidths = new int[]{0};
      gridBagLayout.rowHeights = new int[]{0};
      gridBagLayout.columnWeights = new double[]{1.0};
      gridBagLayout.rowWeights = new double[]{1.0};

Do you've got an idea?

Kind regards
Chris
chrisR
 
Posts: 19
Joined: Thu Jul 23, 2009 5:07 am

Re: Gridbaglayout Design Page Nested Panel shows large gaps

Postby Eric Clayberg » Thu Aug 20, 2009 6:31 am

Please give this a try using the latest Swing Designer v7.1 build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest