views:

190

answers:

1

Hello all
This code inside a JFrame form created in netbeans works fine as i'm trying to put a JCalendar in a panel that i create manually.

JCalendar myCalendar =new JCalendar();
JPanel customPanel = new JPanel();
customPanel.setSize(400, 250);
customPanel.setBorder(new LineBorder(Color.BLACK));
customPanel.add(myCalendar);
this.add(customPanel);

However if i create a panel in netbeans with the help of visual gui builder(matisse) and then use this code

JCalendar calendar2 =new JCalendar();
netbeansPanel.setSize(400, 250);
netbeansPanel.add(calendar2);

the JCalendar is not visible>Any ideas?
Thank you

A: 

Did little research and found the solution :)

Actually when you add components through Netbeans GUI Builder, it is adding components in GroupLayout and in that we have to add the components like this (Got this idea from the generated code by netbeans).

        JCalendar cal = new JCalendar();
        javax.swing.GroupLayout gl = (javax.swing.GroupLayout)jPanel1.getLayout();
        jPanel1.setSize(400, 250);
        gl.setHorizontalGroup(gl.createParallelGroup().addGroup(gl.createSequentialGroup().addComponent(cal)));
        gl.setVerticalGroup(gl.createParallelGroup().addGroup(gl.createSequentialGroup().addComponent(cal)));

Good luck.

RaviG