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 179168

Summary: Embedding JPanel in TopComponent/other JPanel doesn't work with gui builder
Product: platform Reporter: yoosiba
Component: -- Other --Assignee: issues@platform <issues>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: ENHANCEMENT Exception Reporter:

Description yoosiba 2010-01-03 18:42:08 UTC
Briefly issue was discussed here:
http://old.nabble.com/Panel-visualizes-in-JFrame%2C-but-not-in-TopComponent.-td24596495.html#a24597330
http://forums.netbeans.org/post-42417.html

Description with RCP modular application consideration in mind.

When developing Modular Application on Netbeans RCP it would be good to let Module A return JPanel via lookup to Module B that would embed it in its TopComponent (Jpanel in TopComponent). This way Module A hides its implementation of module specific graphic component. Module B just asks for it without knowing its details. This doesn't work if panel in Module B is generated with gui builder.

 For example Module B asks Module A for some panel with chart. When using standard gui generator and lookup mechanism in Module B in TopComponents JPanel we would have:

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanelChart = Lookup.getDefault().lookup(ChartPanelFactory.class).getChartPanel();

        javax.swing.GroupLayout jPanelChartLayout = new javax.swing.GroupLayout(jPanelChart);
        jPanelChart.setLayout(jPanelChartLayout);
        jPanelChartLayout.setHorizontalGroup(
            jPanelChartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 376, Short.MAX_VALUE)
        );
        jPanelChartLayout.setVerticalGroup(
            jPanelChartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 274, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelChart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelChart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>     

Problem is, that when jPanelCharLayout is created, JPanel that was requested is hidden in application and user sees empty JPanel instead.
Workaround is to comment out whole initComponents() method and write its copy without jPanelChartLayout definition and setup or overload initComponets and call overloaded version instead original one. In either case it is not safe or easy to maintain. 

It would be good if netbeans RCP would support this kind of embedding graphical components without such hackarounds.