0

when ı add two panels into a frame last panel i added seen on the screeen how can i show both panels in one frame

5
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by masijade
0

There gone be something wrong with your code. Can you please post it?

PS: Use code tags, press hash "#" sign on post toolbar and paste your code between the tags which will appear

0

It's probobly a layout issue. Try to use something like this

class MyFrame extends JFrame
{
   
    public MyFrame()
    {
    
     setSize(800,600);
     setTitle("MyFrame");

     JPanel panel1 = new JPanel();
     JPanel panel2 = new JPanel();

     Container cp = getContentPane();

[B]     cp.setLayout(new FlowLayout());[/B]

     cp.add(panel1);
     cp.add(panel2);
 
    }
 

}
0

My Example will show two panels.
I just wanted to show him how to add a layout to the frame.
If he hasn't done that he will only see one panel.

0

Well, the contentPane of the the JFrams already has a layout. It simply needs to be used correctly. If you use add without any anchor parameter then according to the documentation
As a convenience, BorderLayout interprets the absence of a string specification the same as the constant CENTER

So, simply calling add(Component) twice, is the same as calling add(Component, CENTER) twice. She should be calling add(Component, CENTER) and add(Component, SOUTH), for example.

Of course, changing the layout (as your post showed) is always an option, but is not, strictly speaking, needed.

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.