简体   繁体   中英

How can I use TabbedPane tab changes to diplay different Panels in an Applet built in NetBeans IDE?

I'm building a Java Applet in NetBeans that has a TabbedPane on the bottom of the applet and a regular Panel on the top. I would like the top Panel to switch depending on which tab is selected on the bottom. (I would attach a screenshot to clarify, but being new here it isn't allowed.)

A Button has ActionPerformed, but a TabbedPane doesn't seem to have StateChange for each of the seperate tabs (at least not readily visible in NetBeans).

Any ideas?

According to here , you can do something like this:

// Create the tabbed pane
JTabbedPane pane = new JTabbedPane();

// Add tabs...; see Adding a Tab to a JTabbedPane Container

// Register a change listener
pane.addChangeListener(new ChangeListener() {
    // This method is called whenever the selected tab changes
    public void stateChanged(ChangeEvent evt) {
        JTabbedPane pane = (JTabbedPane)evt.getSource();

        // Get current tab
        int sel = pane.getSelectedIndex();
    }
});

Then, use some switch statement to direct the flow of the program.

Continuation: Last time I used a JTabbedPane in Netbeans, all that I had to do was to add a new tab and simply build the gui for it. If you are having trouble with this, you might want to take a look at the Card Layout .

If you go through the tabs on the right hand side of your development screen, you should come accross a list of events. What you need to do is to select the appropriate event from that list and Netbeans will do it for you. On the other hand, you can open the .java file (while not open in netbeans) with a text editor (WordPad, NotePad++, etc) modofiy the code you want and save it. When you will open the file back through netbeans, you should see that your changes have been loaded as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM