This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 79967 - Group layout does not set the right size
Summary: Group layout does not set the right size
Status: RESOLVED WONTFIX
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
: 82510 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-11 11:58 UTC by webhsw
Modified: 2006-10-23 15:46 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
screenshot (209.87 KB, image/jpeg)
2006-07-11 12:00 UTC, webhsw
Details
Screenshot 2 (50.90 KB, image/jpeg)
2006-08-09 14:07 UTC, webhsw
Details

Note You need to log in before you can comment on or make changes to this bug.
Description webhsw 2006-07-11 11:58:54 UTC
See the attached screenshot. The GroupLayout does not set the right size if the
form is running. Using such a form in a DialogDisplayer it displays the
Buttonpanel over such a panel.
Comment 1 webhsw 2006-07-11 12:00:23 UTC
Created attachment 31723 [details]
screenshot
Comment 2 Tomas Pavek 2006-08-08 10:57:45 UTC
I've been thinking how we could solve this problem, but with no luck. It is not
a problem of GroupLayout specifically, but rather a more general issue of laying
out components which preferred size of one dimension depends on the actual size
in the other dimension.

Multi-line label that wraps text is such a component. Before it is laid out with
the given width, it computes its preferred size as it would have just one line
(which is the default state). So it returns height of one line. But once its
width is set, the label's preferred height changes. Thus building such layout is
a two-step process. Normally it is not a problem , it happens automatically, but
when you need to determine the preferred size of the whole window (pack() does
this), you get the preferred size after the first pass, which is not correct.
You can fix it by calling pack() once more...

This problem can happen with any component that does some wrapping and does not
have the other dimension clearly defined (e.g. also JList with layout
orientation set to HORIZONTAL_WRAP or VERTICAL_WRAP). It is a problem in
situation when you need the preferred size - you don't right until the layout is
built.
Comment 3 webhsw 2006-08-08 12:45:11 UTC
Sorry, but the form is a JPanel and it does not extend the pack() method. In my
case I use this panel in a DialogDisplayer. Please give me a workaround to fix it!
Comment 4 Tomas Pavek 2006-08-08 13:04:50 UTC
DialogDisplayer gives you a Dialog on which you can call pack(). (Once is 
enough because you get it with the first computatuion of layout already done.)
Comment 5 webhsw 2006-08-09 14:07:30 UTC
Created attachment 32706 [details]
Screenshot 2
Comment 6 webhsw 2006-08-09 14:12:52 UTC
Pack() against the DialogDisplayer does not work! See Screenshot 2 for details. 
Comment 7 Tomas Pavek 2006-08-09 16:29:01 UTC
Ok, I've finally tried it myself ;) It seems the label does not change its mind 
until it is painted. Just computing the layout is not enough. That's how html 
rendering happens to work...

Trying to wait for the label painted is ugly (and you'd see the dialog 
resizing), so better seems just to call paintImmediately on the label. This 
needs to be done _after_ setVisible(true) is called on the dialog, which is a 
problem if the dialog is modal... So overall it might look like this:

final Dialog dialog = DialogDescriptor...
dialog.addComponentListener(new ComponentAdapter() {
    public void componentShown(ComponentEvent e) {
        theLabel.paintImmediately(theLabel.getBounds());
        dialog.pack();
        dialog.removeComponentListener(this);
    }
});
dialog.setVisible(true);

Let me know if this works for you.
Comment 8 webhsw 2006-08-10 08:12:05 UTC
The code you wrote is working! But this solution is a little bit "terrible" and
unacceptable! I think that this absolute a bug in GroupLayout.
I can also fix this problem, if I add below the JPassword component a
JSeparator. Then the dialog is also shown correct, but without the Separator.
I seems that the GroupLayout always suppres parts of the "bottom" Component.

This can also be seen in the FormDesigner:
Build a panel like I used with the "default" space of the "bottom"-JPassword.
Then restart Netbeans and you can see, that the space is gone.
Then add a JSeparator below the JPassword and set the "botton" space again to
default. The Separatot is shown. Restart Netbeans and the Separator is
invisible, but now you have an acceptable "bottom"-border of the panel.

I hope that someone can fix this bug.
Comment 9 Tomas Pavek 2006-08-10 10:07:47 UTC
I can agree with you the solution is weird, but this is definitely a problem of 
the html rendering of JLabel, not of GroupLayout. The JLabel does not provide 
correct preferred size until it is laid-out first and painted. Then the layout 
must be computed again. All the symptomps you describe are result of this. We 
could make the GUI builder to accommodate this in the designer, but we can't 
influence the runtime behavior.

GroupLayout just exposes this problem - with other layout manager you would not 
be able to use the multiline label at all (or you'd have to hardcode its 
preferred size which makes it unusable).
Comment 10 Tomas Pavek 2006-08-11 11:04:34 UTC
Closing. We can't fix nor accommodate the JLabel's html rendering behavior. I'll
write an FAQ entry.
Comment 11 Tomas Pavek 2006-08-14 09:18:47 UTC
*** Issue 82510 has been marked as a duplicate of this issue. ***