日期:2014-05-20  浏览次数:20811 次

CardLayout布局的问题,请问怎么改?小菜求教
首先,请看代码:

//import ... 略去
public class VisualPanel_user {
JFrame jf = null ;
CardLayout card = null ;
public VisualPanel_user() {
JPanel jpN = new JPanel();
JPanel jpW = new JPanel();
JPanel jpC = new JPanel();
card = new CardLayout();

JLabel user_name = new JLabel("hello,"+Login_Cla.user_name);
    JLabel  title = new JLabel(" 欢迎进入系统 ");
    
    user_name.setFont(new java.awt.Font("华文行楷", 0, 30));
    title.setFont(new java.awt.Font("华文行楷", 0, 30));
    jpN.add(user_name);
    jpN.add(Box.createHorizontalStrut(100),"CENTER");
    jpN.add(title,"CENTER");
    jpN.add(Box.createHorizontalStrut(100),"CENTER");
    jpN.setBorder(new Border(){
public Insets getBorderInsets(Component c) {
return new Insets(10,10,10,10);
}
public boolean isBorderOpaque() {
return false;
}
public void paintBorder(Component c, Graphics g, int x, int y,
int width, int height) {
}});
    JScrollPane scroll=new JScrollPane();
    final JTree tree = new JTree();
    DefaultMutableTreeNode  root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode  buy = new DefaultMutableTreeNode();
    DefaultMutableTreeNode  deposit = new DefaultMutableTreeNode();
    DefaultMutableTreeNode  money = new DefaultMutableTreeNode();
    DefaultMutableTreeNode  transfer = new DefaultMutableTreeNode();
    DefaultMutableTreeNode  withdraw = new DefaultMutableTreeNode();
    
    root.setUserObject("管理菜单");
    buy.setUserObject("购买商品");
    deposit.setUserObject("即时存款");
    money.setUserObject("资金查询");
    transfer.setUserObject("即时转账");
    withdraw.setUserObject("即时取款");
    
    root.add(buy);
    root.add(deposit);
    root.add(money);
    root.add(transfer);
    root.add(withdraw);
    
    DefaultTreeModel dtm = new DefaultTreeModel(root);
    
    tree.setModel(dtm);
    scroll.setViewportView(tree);
    jpW.add(scroll);

//     final JPanel p_1 = new UserBuy_Cla();
//     final JPanel p_2 = new UserDeposit_Cla();
//     final JPanel p_3 = new UserMoney_Cla();
//     final JPanel p_4 = new UserTransfer_Cla();
//     final JPanel p_5 = new UserWithdraw_Cla();
    final JPanel p_1 = new JPanel();
    final JPanel p_2 = new JPanel();
    final JPanel p_3 = new JPanel();
    final JPanel p_4 = new JPanel();
    final JPanel p_5 = new JPanel();
    p_1.setBackground(Color.black);