CardLayout 
1.  CardLayout places components (usually panels) on top of each other in a stack like a deck of cards. You see only one at a time, and you can flip through the panels by using another control to select which panel comes to the top
2.  CardLayout is a good layout to use when you have an area that contains different components at different times. This gives you a way to manage two or more panels that need to share the same display space. 
3.  CardLayout is usually associated with a controlling component, such as a check box or a list. The state of the controlling component determines which component the CardLayout displays. The user makes the choice by selecting something on the UI.

解决方案 »

  1.   

    CardLayout 
    1.  CardLayout places components (usually panels) on top of each other in a stack like a deck of cards. You see only one at a time, and you can flip through the panels by using another control to select which panel comes to the top
    2.  CardLayout is a good layout to use when you have an area that contains different components at different times. This gives you a way to manage two or more panels that need to share the same display space. 
    3.  CardLayout is usually associated with a controlling component, such as a check box or a list. The state of the controlling component determines which component the CardLayout displays. The user makes the choice by selecting something on the UI.
      

  2.   

    可以用Borderlayout,事先创建好几个JPanel对象,在点击不同的菜单的单击事件处理方法中,将center区域设置为不同的一个JPanel。
      

  3.   

    也可以布局中央放一个JPanel,换的时候把要换的JPanel扔进中央那个JPanel里就行!
      

  4.   

    1、CardLayout布局非常适合你所想达到的目的。2、使用JLayeredPane,稍微麻烦点,做很多的层,通过菜单来改变层的高度,这样也可以达到你的要求。3、把很多JPanel都添加到一个主JPanel上,初了需要显示的JPanel外其它都设为不可见pane.setVisible(false); ,然后通过菜单来改变setVisible(boolean); 。参考代码:http://expert.csdn.net/Expert/topic/2482/2482750.xml?temp=.8061334<------ 树欲静而风不止 ------>
      

  5.   

    CardLayout布局有没有详细一点的说明
      

  6.   

    我看过了,CardLayout不适合,因为有些东西,我在前一个PANEL里改变了,在下一个PAANEL里面有变化我现在用
    removeall()
    add(..)但是我发现东西多了很乱
      

  7.   

    removeall()
    add(..)确实很烦的
    我自己的项目中的做法是中间是一个JScrollPane各个面板的显示只要scrollPane.setViewportView(pane1)....
      

  8.   

    楼上的办法不错,!
    我们之前的做法也是removeall()和add()
    但不知道用scrollPane.setViewportView(pane1)方法,当切换回之前的panel时,之前那个panel中的数据还存不存在,还是被重新初始化??
      

  9.   

    我觉得上面 kypfos(现在,我该革谁的命) 的方法可行性还是比较大的。你同样也可以在初始化时生成多个jpanel,在不用时把它hide,在用时把它显示出现出来。 JPanel p=new JPanel();
    p.setVisible(false);//p.hide();试试看。
      

  10.   

    用scrollPane.setViewportView(pane1)方法,当切换回之前的panel时,之前那个panel中的数据当然还是存在的,但是在显示的时候panel会调用paint或paintComponent进行重画。
      

  11.   

    还有个问题要问kypfos如果add(new dd(year,month))这个year和month可能在前一个panel中被修改所以当dd要显示时,那个year和month值也被改变了那么scrollPane.setViewportView()时,是否是类同时也被改变
      

  12.   

    scrollPane.setViewportView(pane1)的时候你可以写自己的控制代码比如
    dd d=new dd(year,moth);
    add(d)
    写代码控制
    d.setYear(..)
    d.setMonth(..)
    可放到paint方法中,或其他的操作方式
    你能想到的