0

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 ?"

4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by mohamed moamen
0

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

0

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 ?

0

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 by reubenj: Left something out

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.