karizake
karizake

Reputation: 11

How do I add a custom panel in Netbeans through Code?

I have a custom class that extends JPanel called Node that I want to be able to add to panel MainPanel through code, but the Nodes are not appearing. It works fine with drag and drop, but I want to add more Nodes during runtime.

Upvotes: 0

Views: 505

Answers (1)

camickr
camickr

Reputation: 324108

but I want to add more Nodes during runtime.

When adding components to a visible GUI the basic code is:

panel.add(...);
panel.revalidate();  
panel.repaint();

You need to invoke the layout manager to the component has a size and location otherwise the size is (0, 0) and there is nothing to paint.

Upvotes: 1

Related Questions