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 253047 - GUI builder doesn't add JLayeredPane layers correctly
Summary: GUI builder doesn't add JLayeredPane layers correctly
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.0.2
Hardware: PC Windows 7 x64
: P3 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-17 19:06 UTC by cmolodo
Modified: 2015-09-14 20:06 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Incorrect GUI builder-generated java code (3.11 KB, application/octet-stream)
2015-06-17 19:06 UTC, cmolodo
Details
Correct (manually edited) JLayeredPane code (3.30 KB, text/plain)
2015-06-17 19:07 UTC, cmolodo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cmolodo 2015-06-17 19:06:18 UTC
Created attachment 154270 [details]
Incorrect GUI builder-generated java code

When using the GUI builder with a JLayeredPane that has multiple layers, the generated code to add the layers is incorrect.  

According to the API documentation: "The layer should be set BEFORE adding the child to the parent."  However, the generated code sets the layer AFTER adding the child objects.  This leads to incorrect behavior when repainting lower levels, which get drawn over upper levels.

Attached is a JFrame (LayeredFrame_Bug) with a JLayeredPane illustrating the incorrect generated code and subsequent incorrect behavior.  When the "Change Color" button is pressed, the background color of the lower panel, in the default layer, changes.  This should NOT affect the appearance of the upper panel, which should be in the MODAL_LAYER.  However, the lower panel is redrawn over the upper panel.  Resizing or minimizing/maximizing the frame fixes the display.

Also attached is a correct JFrame (LayeredFrame_Correct), which is almost identical, but has the setLayer() call before adding the panels to the JLayeredPane.  It demonstrates the expected behavior when changing lower panel background colors.

As a side note, the GUI builder used to correctly set the layer when the component was added to the JLayeredPane via add(Component c, Integer layer).  Not sure when this changed, (our old correct code is several years old), but I'm guessing it was when support for layout managers was added to JLayeredPane?
Comment 1 cmolodo 2015-06-17 19:07:18 UTC
Created attachment 154271 [details]
Correct (manually edited) JLayeredPane code
Comment 2 Tomas Pavek 2015-09-09 17:23:18 UTC
This is a really good catch, thanks! It seems like in many cases it does not matter, but in some does and the documentation really says that setLayer should be called before adding.

I've made a fix, should appear in 8.1 (to be released in November), sooner in daily builds (if interested in verifying the fix).

http://hg.netbeans.org/jet-main/rev/cc42cdac6ee1
Comment 3 Quality Engineering 2015-09-10 01:29:46 UTC
Integrated into 'main-silver', will be available in build *201509100002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/cc42cdac6ee1
User: Tomas Pavek <tpavek@netbeans.org>
Log: #253047: layered pane's setLayer code should be generated before the component is added to the container
Comment 4 cmolodo 2015-09-14 20:06:18 UTC
Thank you for the fix, I tested the development build and it works great!  Looking forward to 8.1.