kvarnerexpress 0 Report post Posted October 31, 2005 I am developing a GUI using Netbeans...(Definitely recommended!)...and have a JComboBox which is populated from data from a MySQL database.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 Share this post Link to post Share on other sites
iGuest 3 Report post Posted February 4, 2009 populate combobox and run queryFill JcomboboxThe posts here are very helpful.Am new to programming and I need to generate some reports by selecting the items to query for from comboboxes and run using a button.Can someone help me with code to start me off. Regards-reply by Edna Share this post Link to post Share on other sites