Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JtabbedPane. How do i know on witch tab i am  RSS feed

 
Pedro Neves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i'm experiencing a problem.

I have a JTabbedPane with several Tabs. Each tab has 2 panels and one of the panels have one button, i want that button to be specific for each tab. i mean, if it is tab number one that button its goin do do something, if it is tab 2 it is going to do the opposite. How can i do that? i have an array of Jbuttons, one for each tab. can somebody know how can i diferentiate them for tabs in the eventListener?

Thanks in advance
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, they are different buttons, aren't they? But I don't understand what you mean by "the EventListener"... it sounds like you're only going to have one. It would be much easier for each button to have its own action listener, especially since they are meant to do different things.
 
Pedro Neves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, they are different buttons, aren't they? But I don't understand what you mean by "the EventListener"... it sounds like you're only going to have one. It would be much easier for each button to have its own action listener, especially since they are meant to do different things.



They are buttons stored on a JButton [] because. I have no limit of Tabs and each tab must have one of those buttons, so i though it would be better to store them on an array of Jbuttons. On the EventListener i do something like this:




the problem is that each Tab have a Button (JButton[i]) and all of the JButtons could do diferent things (or not) based on the tab the user is viewing
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. But I don't see why that prevents you from adding a different action listener to each button in the array. Or for having a separate event listener for each of the tabs.
 
Pedro Neves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Okay. But I don't see why that prevents you from adding a different action listener to each button in the array. Or for having a separate event listener for each of the tabs.


How can i do that? thats my point i dont know how to direfentiate it or how to add a different eventListener to buttons with the same name
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> thats my point i dont know how to direfentiate it or how to add a different eventListener to buttons with the same name

they can't have the same name. earlier you said "They are buttons stored on a JButton []...",
so, button[0] is different to button[1] and different to all the others.
simply add your specific listener to a specific button

your subject title "JtabbedPane. How do i know on witch tab i am"
read the docs, and the methods - you 'want' something so it will start with 'get...'
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!