Including more than two Panels in a JFrame?

后端 未结 3 572
忘了有多久
忘了有多久 2021-01-06 06:05

We are working on a project where we encountered a problem with including more than two Panels on the same JFrame .What we want is one Panel above the other.

Can the

3条回答
  •  悲哀的现实
    2021-01-06 06:34

    if you want each of the frames/panels the same size, use the GridLayout, with a grid of 1(column) and 2(rows)

    Frame myFrame;  
    GridLayout myLayout = new GridLayout(2,1);  
    
    myFrame.setLayout(myLayout);  
    
    Panel p1;  
    Panel p2;  
    
    myFrame.add(p1);
    myFrame.add(p2);
    

    if the panels are different size use the BorderLayout.... set the upper frame to "North" and the lower one to "South" or "Center"

    Frame myFrame;  
    
    myFrame.setLayout(new BorderLayout() );  
    
    Panel p1;  
    Panel p2;  
    
    myFrame.add(p1, BorderLayout.NORTH);  
    myFrame.add(p2, BorderLayout.CENTER);  
    

提交回复
热议问题