| Author |
Message |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Why is this cell growing?
Hi, I'm trying to figure out why the cell enclosing "redSkewLabel" is growing horizontally: Code: propertiesPanel.setLayout(new MigLayout(new LC().fill().debug(1000))); propertiesPanel.add(redSkewLabel, new CC().grow(0)); redSkewLabel.setOpaque(true); redSkewLabel.setBackground(Color.BLUE);
In the above code sniplet, propertiesPanel is a JPanel, redSkewLabel is a JLabel. When I enlarge the JFrame the cell is growing horizontally even though the embedded JLabel remains small. Why is the cell growing and how do I prevent it? Thanks, Gili
|
| Tue May 10, 2011 4:33 pm |
|
 |
|
MiG Support
Site Admin
Joined: Mon Dec 06, 2004 4:24 pm Posts: 2485 Location: Sweden
|
 Re: Why is this cell growing?
new LC().fill() means that the grid must fill the panel. You are giving conflicting grow and not grow..
|
| Tue May 10, 2011 4:56 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
MiG Support wrote: new LC().fill() means that the grid must fill the panel. You are giving conflicting grow and not grow.. You're right. Here's what's confusing me: The CheatSheet specifies that the default grow() value for columns is 100, yet my column won't grow unless I explicitly assign it a grow value. I have two columns. If I set: Code: new AC().size("150:300:", 0) then neither column grows. If I set: Code: new AC().size("150:300:", 0).grow(100, 1) the second column grows. The actual component is added as follows: Code: add(right, new CC().grow().spanX().spanY().wrap()); Any ideas? Gili
|
| Tue May 10, 2011 5:11 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
My mistake, I misread the document. If grow() is omitted, the default value is zero. If grow() is specified but its *value* is omitted, the default value is 100.
Gili
|
| Tue May 10, 2011 5:14 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
I am seeing really weird behavior. Given two columns, I specify the following column constraints:
1. grow(100, 0) causes *both* columns to grow 2. grow(100, 1) causes only the right column to grow
Why does growing the left column also affect the right one?
Thanks, Gili
|
| Tue May 10, 2011 5:29 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
Mikael,
I believe this is a legitimate bug in MigLayout. Can you please comment on this issue? Do you need a testcase from me or can you reproduce it on your end?
Thanks, Gili
|
| Fri May 13, 2011 3:59 am |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
Here is a minimal testcase: Code: import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import net.miginfocom.layout.AC; import net.miginfocom.layout.CC; import net.miginfocom.layout.LC; import net.miginfocom.swing.MigLayout;
public class Testcase extends JPanel { public Testcase() { setLayout(new MigLayout(new LC().debug(1000), new AC().grow(), new AC().grow())); setPreferredSize(new Dimension(800, 600));
JPanel growNeither = new JPanel(new MigLayout(new LC().debug(1000))); growNeither.add(new JLabel("left")); growNeither.add(new JLabel("right"), new CC().wrap()); add(growNeither, new CC().grow());
JPanel growLeft = new JPanel(new MigLayout(new LC().debug(1000), new AC().grow(100, 0))); growLeft.add(new JLabel("left")); growLeft.add(new JLabel("right"), new CC().wrap()); add(growLeft, new CC().grow().wrap());
JPanel growRight = new JPanel(new MigLayout(new LC().debug(1000), new AC().grow(100, 1))); growRight.add(new JLabel("left")); growRight.add(new JLabel("right"), new CC().wrap()); add(growRight, new CC().grow());
JPanel growLeftWorkaround = new JPanel(new MigLayout(new LC().debug(1000), new AC().grow(100, 0). grow(0, 1))); growLeftWorkaround.add(new JLabel("left")); growLeftWorkaround.add(new JLabel("right"), new CC().wrap()); add(growLeftWorkaround, new CC().grow().wrap()); }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(new Testcase()); frame.pack(); frame.setVisible(true); } }
The top-right box demonstrates the bug. The bottom-right box demonstrates the expected behavior. Gili
|
| Sun May 15, 2011 8:27 pm |
|
 |
|
MiG Support
Site Admin
Joined: Mon Dec 06, 2004 4:24 pm Posts: 2485 Location: Sweden
|
 Re: Why is this cell growing?
Hello,
I have tested it and it does indeed look like you've found a bug. I'll investigate.
Cheers, Mikael
|
| Sun May 15, 2011 8:58 pm |
|
 |
|
MiG Support
Site Admin
Joined: Mon Dec 06, 2004 4:24 pm Posts: 2485 Location: Sweden
|
 Re: Why is this cell growing?
Oops, sorry. No bug.  The last column's settings is repeated for any column that is not specified. This means that the second column, which hasn't got any grow or size constraints, gets the same settings as the last one which is the first. This is more clear and intuitive in the strings version Code: setLayout(new MigLayout("debug 1000", "[grow 100]"));
vs. Code: setLayout(new MigLayout("debug 1000", "[grow 100][]"));
Normally I try never to define the grid using column and row constraints. I try to only use CC. Cheers, Mikael
|
| Sun May 15, 2011 9:05 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
MiG Support wrote: Oops, sorry. No bug.  The last column's settings is repeated for any column that is not specified. This means that the second column, which hasn't got any grow or size constraints, gets the same settings as the last one which is the first. Good catch! Is it possible to mention this in the AC.grow() Javadoc? MiG Support wrote: Normally I try never to define the grid using column and row constraints. I try to only use CC. When I tried something similar it didn't work: http://migcalendar.com/forums/viewtopic.php?p=7995#p7995 new CC().grow() had no effect unless I also specified new AC().grow(). What exactly did you have in mind? Thanks, Gili
|
| Sun May 15, 2011 9:14 pm |
|
 |
|
MiG Support
Site Admin
Joined: Mon Dec 06, 2004 4:24 pm Posts: 2485 Location: Sweden
|
 Re: Why is this cell growing?
Grow means the component should grow to the max extent of the cell it's in but it doesn't affect the cell's size. push is what you're looking for. It makes the cell want to grow as well.
Cheers, Mikael
|
| Sun May 15, 2011 9:17 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
MiG Support wrote: Grow means the component should grow to the max extent of the cell it's in but it doesn't affect the cell's size. push is what you're looking for. It makes the cell want to grow as well.
Cheers, Mikael Wow. That works great  Thanks! It would be great if the documentation for Component-"grow" contained the sentence you wrote above. I find that sometimes the problem with MigLayout is that you have to read the full documentation in order to understand why feature X isn't working as you expected. If you had cross-references like the one above it would make it easier for new users to learn. Thanks, Gili
|
| Sun May 15, 2011 10:29 pm |
|
 |
|
MiG Support
Site Admin
Joined: Mon Dec 06, 2004 4:24 pm Posts: 2485 Location: Sweden
|
 Re: Why is this cell growing?
Well, it's hard to write all cross referencing information in all places.
Also, I don't have much time for MigLayout nowadays. It was fun until Sun/Oracle clearly indicated that they rather write their own stuff. Now there's no return for the time (which translates to money for a consultant like me) spent.
I tend to wait until I at least have a days work until I do something or the admin part will be too high.
Cheers, Mikael
|
| Sun May 15, 2011 10:40 pm |
|
 |
|
cowwoc
Joined: Mon Aug 23, 2010 6:24 am Posts: 54
|
 Re: Why is this cell growing?
MiG Support wrote: Well, it's hard to write all cross referencing information in all places.
Also, I don't have much time for MigLayout nowadays. It was fun until Sun/Oracle clearly indicated that they rather write their own stuff. Now there's no return for the time (which translates to money for a consultant like me) spent.
I tend to wait until I at least have a days work until I do something or the admin part will be too high.
Cheers, Mikael Fair enough. Have you given any thought to attracting more committers to this project? Two things I'd look for are a public bug tracking system and migration to Mercurial. This would facilitate branching and contributing patches. Gili
|
| Mon May 16, 2011 5:56 pm |
|
 |
|
MiG Support
Site Admin
Joined: Mon Dec 06, 2004 4:24 pm Posts: 2485 Location: Sweden
|
 Re: Why is this cell growing?
I have thought about it. Though I don't know Mercurial and I had help setting up the Maven thing and it's very very brittle...
Also, I don't want new features in since people already think there's too much functionality. That would be a hard thing to sell to committers..
Cheers, Mikael
|
| Tue May 17, 2011 1:10 am |
|
|