aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Code review Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Code review" Watch "Code review" New topic
Author

Code review

Gareth Billett
Greenhorn

Joined: Apr 02, 2013
Posts: 2
Can someone please test/review this code. I apologize if the code is unconventional as I am new to JAVA and learning as I go, but I would appreciate any constructive critisism.

The application is working as expected, however I have a bug which eludes me. If you add 2 records and delete record 1, the program will fail with the following:


Here is the full code, any help or tips would be greatly appreciated:
Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 169
    
    1

I think you are trying to delete a object in JComboBox.
You deleting command is fine. But there is a problem.

After you have deleted a object in JComboBox, the selected item is changing implicitly. That's because JComboBox cannot find that previously selected item as it has been deleted. Therefore JComboBox select the previous item.
But you have override itemStateChanged() method. As the previously selected item is deselected and new item is selected, overridden method is called twice. (But it is not the problem here)


Here the variable 'selected' is the problem. If you select 2nd item selected=1. After you delete 2nd item, JVM calls itemStateChanged() method. Then comboBox.getItemAt(selected) will give runtime error as 'selected = 1'.


Ramesh-X
Gareth Billett
Greenhorn

Joined: Apr 02, 2013
Posts: 2
Thanks Ramesh I see the issue.
 
 
subject: Code review