I would like to do know two things really...
1. In Netbeans is there somewhere on the properties of the JComboBox where I can point to a method I have that returns a resultset so it automatically knows what I want to be the items within the JComboBox.
I guess I am looking for an option very similar to what exists in Macromedia Dreamweaver and the way you select a textfield for example, point to your recordset/query, and then specify it's default values (possibly a surname from the query)
If someone has come across something like that in Netbeans and could tell me...
2. I have listed my code below, it works so not asking for people to fix it, I just wanted to know if this is the correct way to go about populating the combo box with data. I am new to Java and obviously wery about whether or not I am doing things right.
(Did not include all my GUI stuff)
Code:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class preadvisorLogon extends javax.swing.JFrame {
/** Creates new form preadvisorLogon */
public preadvisorLogon() throws Exception{
mdbc=new MyDBConnection();
mdbc.init();
Connection conn=mdbc.getMyConnection();
stmt= conn.createStatement();
ResultSet rs = getAgents();
//THIS BUILDS MY GUI, MUCH CODE TAKEN OUT
initComponents();
//Fill JComboBox with values from query
updateJComboBox(rs);
}
public ResultSet getAgents() {
ResultSet rs=null;
try{
rs=stmt.executeQuery("SELECT `Agent ID`,`Description` FROM `aar");
}
catch(SQLException e){}
return rs;
}
public void updateJComboBox(ResultSet rs) throws SQLException {
while(rs.next())
{
jcmbAgents.addItem(rs.getString("Description"));
}
}
}
thanks,kvarnerexpress














