• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JTabbedPane selection problem

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works fine for me.
Is that your real code?
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic