cerco di spiegarvi la situazione.
con questo metodo passo i dati da una riga di una JTable ad un altro JFrame:
nel frame:codice:ArrayList<String> list = new ArrayList<String>(); int numCol = model.getColumnCount(); Object value = null; for (int i = 0; i < numCol; i++) { value = tableData.getValueAt(tableData.getSelectedRow(), i); list.add(value.toString()); } FormModifica form = new FormModifica(list); form.setVisible(true);
e fin qui tutto bene.codice:public class FormModifica extends javax.swing.JFrame { private DBManager dbman = DBManager.getInstance(); private String[] valori; private String id; private String name; private String author; private String editor; private String price; private String isbn; private String note; public FormModifica(ArrayList<String> list) { valori = (String[]) list.toArray(new String[list.size()]); id = valori[0]; name = valori[1]; author = valori[2]; editor = valori[3]; price = valori[4]; isbn = valori[5]; note = valori[6]; initComponents(); setLocationRelativeTo(null); } .....
in questo frame ho una jcomboxo che riempi da db mysql:
codice:public ArrayList fillAuthor() throws SQLException, ClassNotFoundException, IOException { ArrayList list = new ArrayList(); conn = DBManager.getInstance().takeConnection(); CallableStatement cstmt = conn.prepareCall("{ CALL getAuthor() }"); ResultSet rs = cstmt.executeQuery(); while (rs.next()) { list.add(new ModelAuthor(rs.getInt("author_id"), rs.getString("author_name"))); } cstmt.close(); return list; }anche qiu tutto bene.codice:private void fillAuthor() throws SQLException, ClassNotFoundException, IOException { comboAuthor.addItem("*"); ArrayList listA = dbman.fillAuthor(); for (Object objA : listA) { comboAuthor.addItem(objA); } comboAuthor.setSelectedItem(author); // non funziona }
quello che nn riesco a fare è settare l'item di default uguale alla String author.
in pratica la JCombo si riempie tranquillamente, al jframe arriva il valore author senza problemi ma poi nn lo setta.
dove sbaglio??

Rispondi quotando