刷新JTabbedPane中的选项卡内容

时间:2014-10-23 01:26:02

标签: java swing jpanel jtabbedpane

我正在制作简单的Java TabbedPane GUI。我希望我的标签内容能够更新面板中的事件(例如,单击标签2 JPanel中的按钮。

以下是我的代码:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import java.awt.*; //  Needed For the Defiantions Of the Dimentions
import javax.swing.event.*;
import java.awt.event.*;  // Needed to handle window close event


public class UserTabPan extends JFrame {
    String userName;

    public UserTabPan(String Uname,Float CKBalance,Float SABalance) {

        userName=Uname;

        //Basic Frame Related Definations
        setSize(500, 400); // Sets Size Of the Necessary Windows

        //get screen size and set the location of the frame
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension d = tk.getScreenSize();
        int screenHeight = d.height;
        int screenWidth = d.width;
        setLocation( screenWidth / 4, screenHeight / 4);

        setTitle("Tabbed Pane");

        //Create The Tabbbed Pane
        JTabbedPane jtp = new JTabbedPane();
        Container contentPane = getContentPane(); //add a panel to a frame
        contentPane.add(jtp);

        //Basic Tabs , each one is a panel
        //Tab Panel 1
        JPanel jp1 = new ViewBalanceBO(userName,CKBalance,SABalance);

        //Tab Panel 2
        JPanel jp2 =new TransferMoneyBO(userName);

        //Tab Panel 3
        JPanel jp3=new DepositBO(userName);

        //Tab Panel 3
        JPanel jp4=new WithDrawBO(userName);

        //Tab Panel 4
        JPanel jp5= new InquireTransactionBO(userName);

        //Add Both Tabs to Panle now
        jtp.addTab("Overview", jp1);
        jtp.addTab("Transfer Money", jp2);
        jtp.addTab("Deposit", jp3);
        jtp.addTab("WithDraw", jp4);
        jtp.addTab("View Transactions", jp5);

         addWindowListener (new WindowAdapter()  //handle window closing event
         {  public void windowClosing (WindowEvent e)
            { System.exit(0);
            }
         });
    }
}

例如,如果在WithDraw选项卡中单击了按钮,则应重新初始化“查看事务”选项卡。

我怎么能实现这个目标?

0 个答案:

没有答案