Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JTabbedPane selection problem  RSS feed

 
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!!

});
 
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?
 
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!