Bird89du 1 de jun. de 2009
posta um trecho do seu código e o erro que retorna
abs
vanderlanio 1 de jun. de 2009
Pode sim , só interar sua coleção colega !
tipo :
for ( String str : listStrings )
{
seuObject.addItem(str) ;
}
Marky.Vasconcelos 1 de jun. de 2009
Implemente um ComboBoxModel no lugar do DefaultTableModel que provavelmente voce esta tentando usar.
Fica muito mais interessante.
brunorota 1 de jun. de 2009
public class EclusaDB (){
public ArrayList getDadosCombo (){
ArrayList dados = null ;
String item , cod , nome ;
int i = 0 ;
String sql = "SELECT * FROM eclusas" ;
try {
Connection conn = ConnectionDB . getConnection ();
Statement stm = conn . createStatement ();
ResultSet rset = stm . executeQuery ( sql );
while ( rset . next ()){
cod = String . valueOf ( rset . getInt ( "codEclusa" ));
nome = rset . getString ( "nomeEclusa" );
item = cod + " - " + nome ;
dados . add ( item );
}
} catch ( Exception e ){
e . printStackTrace ();
}
return dados ;
}
}
Agora a classe GUI
public JComboBox getComboEclusa () {
if ( comboEclusa == null ) {
comboEclusa = new JComboBox ( new EclusaDB () .getDadosCombo ()) ;
comboEclusa .setBounds ( 200 , 100 , 200 , 30 ) ;
comboEclusa .addMouseListener ( this ) ;
}
return comboEclusa ;
}
erro
Exception in thread "main" java . lang . Error : Unresolved compilation problem :
The constructor JComboBox ( ArrayList ) is undefined
at ClassesGUI . ItemGUI . getComboEclusa ( ItemGUI . java : 204 )
at ClassesGUI . ItemGUI . getContainer ( ItemGUI . java : 120 )
at ClassesGUI . ItemGUI . initialize ( ItemGUI . java : 56 )
at ClassesGUI . ItemGUI .< init > ( ItemGUI . java : 51 )
at ClassesGUI . ItemGUI . main ( ItemGUI . java : 126 )
Ae galera se alguem puder me ajudar
Falows
vanderlanio 1 de jun. de 2009
public JComboBox getComboEclusa () {
if(comboEclusa == null){
comboEclusa = new JComboBox() ;
comboEclusa.setBounds(200, 100, 200, 30) ;
comboEclusa.addMouseListener(this) ;
List list = new EclusaDB().getDadosCombo() ;
for(String str : list ) {
comboEclusa . addItem ( str );
}
}
return comboEclusa ;
}
Só pra funfa :lol:
brunorota 2 de jun. de 2009
Ae galera achei uma solução
public JComboBox getComboEclusa () {
if ( comboEclusa == null ) {
comboEclusa = new JComboBox ( new Vector ( new EclusaDB () .getDadosCombo ())) ;
comboEclusa .setBounds ( 200 , 100 , 200 , 30 ) ;
comboEclusa .addMouseListener ( this ) ;
}
return comboEclusa ;
}
Obrigado a todos pela atenção
^^