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

JTabbedPane selection problem  RSS feed

 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using a JTabbedPane and in the changeListener(), I have the code to do some operation if the selected tab name is of a particluar name. But the stateChanged() method is called multiple times for a single selection. Any idea of how to restrict this?

Here is my code -

---------------------------------------------------------------

tabPane.addChangeListener(new ChangeListener(){

public void stateChanged(ChangeEvent arg0) {

String tabName = tabPane.getTitleAt(tabPane.getSelectedIndex());

if (//condition)
{
// do some operation
}

}
----------------------------------------------------------------

Please clarify!

thanks in advance!!

});
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine for me.
Is that your real code?
 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this example
for me this works correct I mean one selection = one stateChanged invocation if this doesn't help, provide more sourcecode of your appplication.
 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, this is the code I am using. Since I am using a JoptionPane inside the if condition, and the since the tabbedPane is getting selected automatically by the program after I select it once, the JoptionPane appears multiplt times everytime after I press OK in the JoptionPane.

Any idea what the problem is?

Thanks in advance!!
 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is possible share Your code.
It's hard to work out anything if can't see full source.
I think the bug is somewhere else in Your code.

Check Your Private Messages from time to time
 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Yes, its basically because I have the changeListener called inside a for loop which was the cause of this. Now I have changed this and it works perfectly fine.

Thanks for your help!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!