Bug 179168 - Embedding JPanel in TopComponent/other JPanel doesn't work with gui builder
Embedding JPanel in TopComponent/other JPanel doesn't work with gui builder
Status: NEW
Product: platform
Classification: Unclassified
Component: -- Other --
6.x
PC Windows XP
: P3 (vote)
: TBD
Assigned To: issues@platform
issues@platform
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-03 18:42 UTC by yoosiba
Modified: 2010-01-03 18:42 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo