View unanswered posts | View active topics It is currently Wed Apr 26, 2017 1:22 am



Reply to topic  [ 6 posts ] 
 Absolute positioning corrupts sizing of grid components 
Author Message

Joined: Thu Jun 28, 2012 12:22 am
Posts: 3
Post Absolute positioning corrupts sizing of grid components
Hello,

In several places in our application we use absolute positioning to tweak the location of a component. Since upgrading to MigLayout 4.2, we have noticed that these layouts are all broken; specifically, some components in the grid are not getting the correct size. If we don't add the absolutely positioned component to the layout, all components are sized correctly.

When this happens, if you do something that triggers a revalidate like re-size the containing window, the layout seems to recalculate and then gets the sizes right. I have included a simple class that demonstrates.

It is my understanding that grid layout and absolute positioning are meant to be used together without any problems. Is this a bug, and if so can you recommend a workaround? I took a quick look at the source but could not easily find the problem. Any advice on how to correct this would be much appreciated.

Thanks,
Ben

Demo code:

Code:
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import net.miginfocom.swing.MigLayout;

public class MigBugTest extends JPanel
{
   public MigBugTest()
   {
      setLayout(new MigLayout("insets dialog"));

      JButton button = new JButton("Button");

      //If you comment this out, the text area will size correctly.
      add(button, "pos n text.y text.x2 n");

      /*
       * This text area should grow horizontally and vertically, but it won't
       * as long as the button is included, unless you resize the frame to
       * force a re-layout.
       */
      JTextArea text = new JTextArea("Some text");
      add(text, "id text, push, grow");
   }

   public static void main(String[] args)
   {
      JFrame frame = new JFrame("Test");
      frame.setSize(new Dimension(300, 300));
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setContentPane(new MigBugTest());
      frame.setVisible(true);
   }
}


Thu Jun 28, 2012 12:49 am
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Absolute positioning corrupts sizing of grid components
Hello,

Have you tried to put the absolute positioned components last? Since they depend on the position on the components in the grid it is good if they are calculated first.

Saying that if it worked before it is probably a regression. Which version did it work correctly?

Cheers,
Mikael


Thu Jun 28, 2012 9:03 am
Profile WWW

Joined: Thu Jun 28, 2012 12:22 am
Posts: 3
Post Re: Absolute positioning corrupts sizing of grid components
Hi Mikael,

Thanks for the quick reply.

The reason for adding the button first is to get the desired Z-order. The button will only draw over the text area if it comes first in the container's component array. I tried adding it second just to see if that makes a difference, but it doesn't. I also tried using add(Component, Object, int) to add the button second while setting its position in the order manually... the bug still happens.

We upgraded to 4.2 from 2.5.8, but I did some testing and it looks like the last version to work correctly was 3.7.3.1.

Regards,
-Ben


Thu Jun 28, 2012 4:42 pm
Profile

Joined: Thu Jun 28, 2012 12:22 am
Posts: 3
Post Re: Absolute positioning corrupts sizing of grid components
A few corrections to my statements above:

-I don't see a 2.5.8 in the downloads section of the MiG site, so it seems my records about our previous version may be wrong. Therefore, I'm not sure exactly which version we were using before the upgrade.

-While 3.7.4 is the version that breaks the demo code I posted here, I discovered later that the more complex layouts that are breaking in our application seem to stop working even earlier, on the change from 3.6 to 3.6.1.

-Ben


Fri Jun 29, 2012 1:37 am
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Absolute positioning corrupts sizing of grid components
Ok, then I put this in the todo list.

Thanks!

Cheers,
Mikael


Fri Jun 29, 2012 9:06 am
Profile WWW
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Absolute positioning corrupts sizing of grid components
Hello,

After doing several other fixes this seems to be working as well. At least on OS X.

Please check the next version due in a week or so.

Cheers,
Mikael


Fri Feb 22, 2013 4:20 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.