Link to home
Start Free TrialLog in
Avatar of RicardoVGomes
RicardoVGomes

asked on

JAVA -> Combo Boxes

Hello,

I have 2 combo boxes and want one do something when a component is chosen on the other one.

ComboBox A -> Tables from a database

ComboBox B -> Columns from Table in ComboBox A

I can get the tables in CombBox A.... and the columns from a table....

I need the structure of how to start this and where do I put the code..... Think it will be something like :

ComboTable.addActionListener....................
Avatar of RicardoVGomes
RicardoVGomes

ASKER

This is the code I'm using... but when I choose a table in the comboBox on my application... nothing happens...

ComboTable.addActionListener(new selectionListener(){
                  public void valueChanged(ActionEvent event) throws SQLException {
                        
                  String table = (String) ComboTable.getSelectedItem();
                  
                  
                  String query = "SELECT * FROM " + table;

                  theStatement = Data_Extraction.con.createStatement();
                  rs = theStatement.executeQuery(query);
                  ResultSetMetaData rsmd = rs.getMetaData();
                  
              int numColumns = rsmd.getColumnCount();
                  
              for (int i=1; i<numColumns+1; i++) {
                  String columnName = rsmd.getColumnName(i);         
                  ComboColumn.addItem(columnName);
              }                   
                  
            }
            });
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks ;)
:-)