Solved

JAVA -> Combo Boxes

Posted on 2007-04-11
4
182 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network + 7 80
groupSum5 challenge 5 68
oracle 11g 23 46
even odd program using while loop 3 25
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

929 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

12 Experts available now in Live!

Get 1:1 Help Now