By Geertjan on Jul 30, 2011
I blogged a few weeks ago about how you can create a menu bar that overrides the NetBeans Platform's menu bar. (Read about it here.) And, in your own menu bar, you can align the components to the right and create a Web-like effect for mousing over the menus. (Read about that here.)
But I learned something else related to all that this week. Here's the problem that started my new "learning moment":
As you can see, there's a small space to the right of "Welcome Guest >>", i.e., the upper part of the menu bar is not correctly aligned with the lower part.
I'm using MigLayout above. So I contacted Mikael Grev from MigLayout to ask him what might be causing the above problem. Then he told me about the "debug" command. OK, so I added "debug" to the MigLayout command, as shown below:
setLayout(new MigLayout("debug, nogrid, align right"));
Now run the app again and I saw this:
Wonderful. Now you can see the bounds of the whole layout and the bounds the components get. I can now see that there's some extra space at the end of the upper part of the menu bar. In this case, the upper part is a JPanel constructed in the Matisse GUI Builder. So I opened that in the IDE:
As you can see, there some extra space at the right side of the panel. So I closed up that space by resizing the panel:
And then I ran the app again, with this result:
Hurray. The space is removed and now everything aligns correctly. Also notice that the space between the upper and lower part is now smaller, because I used "wrap 1" instead of "wrap", so I imagine that the default wrap is bigger than 1 and by using 1 I was able to decrease the difference between the two parts of the menu bar.
Then just remove the "debug" command and everything is exactly as I wanted it:
Thanks a lot Mikael for your support and your great layout manager!