Solved

JAVA -> Combo Boxes

Posted on 2007-04-11
4
184 Views
Last Modified: 2010-03-31
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....................
0
Comment
Question by:RicardoVGomes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:RicardoVGomes
ID: 18892032
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);
              }                   
                  
            }
            });
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 18893101
You're mixing your listeners. Should be

ComboTable.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        //  Code in here
    }
});
0
 

Author Comment

by:RicardoVGomes
ID: 18893190
Thanks ;)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18893197
:-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question