简体   繁体   中英

java: jTabbedPane tab clicked event

    mainPane.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            mainPaneMouseClicked(evt);
        }
    });

    private void mainPaneMouseClicked(java.awt.event.MouseEvent evt) {                                      
    System.out.println("hahahahahahhaha");
}   

The code above triggers when I click anywhere in the panel, not just the tab. How do I change it to just fire when the tab is clicked

Also, will I be overriding anything JTabbedPane is doing when a tab is clicked?

You Could...

Use a ChangeListener to detect when the tab selection changes and use something like getSelectedIndex to determine which tab has been selected

You Could...

Instead of moving the JTable from one tab to another, create an instance of a JTable for each tab and share the TableModel between them

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