• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Capture a Tab Click on JTabbedPane  RSS feed

 
Robin Harriet
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, folks.
I'm confused about how to capture (or listen for) a click on a tab of a JTabbedPane. Do I need to register a MouseListener to capture the click and also a MouseMotionListener to determine that the cursor is in the tab portion of the JTabbedPane?
Thanks in advance.
Robin
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what you need to do... if you just need to listen for when tabs get changed, you can use a ChangeListener. If you need to determine when the mouse cursor has moved over a tab, you will probably have to use a MouseMotionListener. If you are interested in getting the actual mouse click you will need to use a MouseListener...

If you are just listening for the actual mouse click, you just need a MouseListener...

-Nate
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone provide example code that detects the click of a JTabbedPane.
Thanks,
Rob
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
Here's a code example that deals with a click on a JtabbedPane... In my example there are two panes. If one is clicked a menu is disabled .

private void jTabbedPaneMouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:

if (jTabbedPane.getSelectedIndex() == 0){
VMenu.enable();
}
else{
VMenu.disable();
}

}
Kristof
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please please post the entire example.
Thanks again.
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem, I got it to work, thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!