Re: JComboBox with IDentifiers
Sax@DIST wrote:
here I am again with another amazing trouble! 08-)
I need to create a JComboBox containing a list of Items, each of which has its own IDentifier!
So: when I select an Item of the JComboBox, I need to get its IDentifier (ie: its ID in a DataBase Table).
I wrote the following four classes example, and I hope this could help someone else with my same needs!
It would be a lot more useful if your code followed the Java Coding Conventions.
More seriously, you fail to respect that GUI actions must happen on the EDT.
It's a rookie mistake.
Idioms like:
String l_nam;
l_nam = this.m_jsx_java_nam;
return( l_nam );
should be replaced with the more readable
return this.jsxName;
Why create a throwaway reference?
Why the redundant parenteses on the return value?
You use code comments in an unusual way, and worse, in lieu of Javadoc comments.
}//constructor
rather than
/**
* Constructor.
*/
Import-on-demand is not a best practice.
import java.util.*;
Comments should actually provide information.
///////////////////////////////////////////////////////////////////
//
// Class.
//
Really?
Declare the widest type applicable. In particular, prefer interfaces to concrete types.
ArrayList<JSX_JAVA_NamVal> m_namval_list;
should be
List<JsxName> names;
Which brings up the point that variables should be named in terms of the problem
domain, not the implementation domain. The fact that the variable is a list in this
case should not be part of the name.
Variables should be scoped as locally as applicable, and declared as close as
convenient to their point of use.
None of this:
private void UpdateIndexAndIdentifier( )
{
Integer l_selectedIndex ;
Integer l_selectedIDentifier ;
String l_index_str ;
String l_identifier_str ;
Setting member variables to their default values in initializers or constructors is usually
unnecessary and always redundant.
this.m_jsx_java_val = 0;
You should fix these issues before proffering your code to the programming public.
As it stands your code is not professional.
--
Lew