• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

e.getSource() question

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How do I stop events coming from cbSKU and cbSubCategory?
Here e.getSource() returns JComboBox rather than cbSKU or cbSubCategory.
Any ideas?
Thanks
Jack
 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean with "to stop "?
Anyway, you added an anonymous class instance to a specific component. As consequence of this, All listened events may have only a source, i.e. the component you added the listener to. So checking the source of the event is useless. It would ne different if you had added an instance of ItemListener which were shared among more than a single component.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change the || on line 6 to &&:

Unless cbSKU == cbSubCategory, your if condition will always be true. After all, (assuming X != Y), something is either not X, or not Y, or not X and not Y. What you want is that the something is not X and not Y.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jacky Luk wrote:Here e.getSource() returns JComboBox


No, it doesn't. It returns the source of the event: cbCategory.

System.out then prints cbCategory.toString().
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting this while I want to change the SKU, then the category and subcats will be reset.
And changing cats will setup SKUs and subcats and so on so forth.
There might still be bugs in it.

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException

 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the java docs for ConcurrentModificationException to see why it's being thrown (you should always check the docs for any exception you get).
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody,
I notice that there is a logical bug in my program.
Now I have fixed that, it works okay now.
Jack
reply
    Bookmark Topic Watch Topic
  • New Topic