i'm use Netbeans
i create JframForm and add a panel to it ,and create new jpanel and add components to it like buttons & textboxs ,finally I'm add the panel 2 to panel 1 but the components of panel 2 not appear and their is no errors.
"how i add the 2nd panel and their components to the 1st one ?"

i'm use Netbeans
i create JframForm and add a panel to it ,and create new jpanel and add components to it like buttons & textboxs ,finally I'm add the panel 2 to panel 1 but the components of panel 2 not appear and their is no errors.
"how i add the 2nd panel and their components to the 1st one ?"

Without posting your code it's hard to guess how your program should work

Without posting your code it's hard to guess how your program should work

myPanle class

public class CustomPanel extends JPanel {

JButton ml = new JButton("my");

    @Override
    public Component add(Component comp) {
        return super.add(ml);
    }
}

main class & form

public class Main  {
    public static void main(String[] args) {
      JFrame window = new JFrame();
      CustomPanel m = new CustomPanel();
      JPanel myPan = new JPanel();
      myPan = m ;
		window.setSize(700, 700);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.add(myPan);
		window.setVisible(true);
	}
    }

why components of custompanl not appear in mypan ?

You should probably try adding the CustomPanel instance to the new panel, in your case the instance is myPan.

myPan = m;

Just copies the reference of m to myPan, right now you adding both panels to the frame.

myPan.add(m);

might work

Then add myPan to the frame so

window.add(myPan);

Edited 4 Years Ago by reubenj: Left something out

You should probably try adding the CustomPanel instance to the new panel, in your case the instance is myPan.

myPan = m;

Just copies the reference of m to myPan, right now you adding both panels to the frame.

myPan.add(m);

might work

Then add myPan to the frame so

window.add(myPan);

i do that nw but the components still not appear , and there is no errors

This article has been dead for over six months. Start a new discussion instead.