Solved

JAVA -> Combo Boxes

Posted on 2007-04-11
4
181 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
  • 2
  • 2
4 Comments
 

Author Comment

by:RicardoVGomes
Comment Utility
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
Comment Utility
You're mixing your listeners. Should be

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

Author Comment

by:RicardoVGomes
Comment Utility
Thanks ;)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
sumHeights  challenge 17 59
triangle challenge 4 75
wordmultiple challenge 12 89
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now