Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I hope that all of thing is good.

Today, I have facing problem regarding NetBean IDE.

I am create two seperate classes one is MyPanel.java and Frame.java.

MyPanel.java is extend from JPanel

When I am create GUI of JPanel using Netbeans. I am want to simple add it into my main Frame.java class.

I am already achive this task whenever using Notepad for doing this all stuff

Java
JPanel panel = new JPanel();
...

this.add(panel);
this.setVisible(true);


I JPanel is visible on my main class. But my main problem is when I am doing same work on Netbeans JPanel is not showing on main ContentPane. and Netbean is not shwoing any error as well.

My all component(button, TextField, RadioButton etc) is added on MyPanel.java class. I am simply add this component into main Frame.java Class.

I hope that you have give me good and positive reply soon.

Best Regards,

Frame.java class
Java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    MyPanel jPanel2 = new MyPanel();
  this.add(jPanel2);
    jPanel1.setVisible(false);

    jPanel2.setVisible(true);



}
Posted

you need to update your GUI after you make those changes. A call for JFrame.revalidate()[^] will do the trick.
 
Share this answer
 
when you add any element in Jframe using netbeans, netbeans add this component using its complex layout(see the auto generated code). So when you simply add any element using
Java
this.add(jPanel2);
,its not appear in the frame.because it is not added to the frame what netbeans use to layout any component. So the best way is that do not add the panel directly in jframe instead first add a jscrollpane in jrame. And then add the required component(jpanel) in scrollpane.
Java
jscrollpane.setViewportView(jPanel))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900