• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

TabbedPane exit

Could someone show me how to make a Tab that says "Exit" and when you click on it, it exits the program?
0
Dmitriy
Asked:
Dmitriy
  • 2
  • 2
1 Solution
 
vivexpCommented:
Hi,

if jtp is a JTabbedPane, add the change listener like this

class aa implements ChangeListener{

public   aa(){

///code
    jtp.addChangeListener (this);

///code
}

 public void stateChanged(ChangeEvent e){
       System.out.println (" change occurred at " + jtp.getSelectedIndex ());
// Get the index of  the tab say(1)
       if(jtp.getSelectedIndex ()==1){
        System.exit (0);
       }


}

0
 
DmitriyAuthor Commented:
Adjusted points to 50
0
 
DmitriyAuthor Commented:
How do I import ChangeListener?  I get a message that the interface not found.

Here is what I have so far... I made two tabs that have different properties.  One of them has name Exit.  

tabbedPane.addTab("Exit",null,panel3, "Exit");
where panel3 is Component type, which will have a function Exit().  This function will have to have the necessary code to exit the program. Is it possible to make it in form of a function instead of a separate class?
0
 
vivexpCommented:
Hi,
    Try this out import javax.swing.event.*;  

Best of luck
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now