Modifying code so that JCheckBox can be used instead of JComboBox

Hello.

how can I modify the following code so that JCheckBox can be used instead of JComboBox?

Thanks.

import javax.swing.*;

import java.sql.*;

import java.awt.*;

import java.awt.event.*;

publicclass Exercise32_6extends JApplet{

private JComboBox jcboTableName =new JComboBox();

private JTextArea jtaResult =new JTextArea();

private JButton jbtShowContents =new JButton("Show Contents");

private Statement stmt;

publicvoid init(){

initializeDB();

jbtShowContents.addActionListener(new java.awt.event.ActionListener(){

publicvoid actionPerformed(ActionEvent e){

jbtShowContents_actionPerformed(e);

}

});

JPanel jPanel1 =new JPanel();

jPanel1.add(new JLabel("Table Name"));

jPanel1.add(jcboTableName);

jPanel1.add(jbtShowContents);

this.getContentPane().add(jPanel1, BorderLayout.NORTH);

this.getContentPane().add(new JScrollPane(jtaResult), BorderLayout.CENTER);

}

privatevoid initializeDB(){

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("Driver loaded");

Connection connection = DriverManager.getConnection("jdbc:odbc:VideoLibrary");

System.out.println("Database connected");

stmt = connection.createStatement();

DatabaseMetaData dbMetaData = connection.getMetaData();

ResultSet rsTables = dbMetaData.getTables(null, null, null,new String[]{"TABLE"});

System.out.print("User tables: ");

while (rsTables.next()){

jcboTableName.addItem(rsTables.getString("TABLE_NAME"));

}

}

catch (Exception ex){

ex.printStackTrace();

}

}

privatevoid jbtShowContents_actionPerformed(ActionEvent e){

String tableName = (String)jcboTableName.getSelectedItem();

try{

String queryString ="select * from " + tableName;

ResultSet resultSet = stmt.executeQuery(queryString);

ResultSetMetaData rsMetaData = resultSet.getMetaData();

for (int i = 1; i <= rsMetaData.getColumnCount(); i++){

jtaResult.append(rsMetaData.getColumnName(i) +"");

}

jtaResult.append("\n");

while (resultSet.next()){

for (int i = 1; i <= rsMetaData.getColumnCount(); i++){

jtaResult.append(resultSet.getObject(i) +"");

}

jtaResult.append("\n");

}

}

catch (SQLException ex){

ex.printStackTrace();

}

}

publicstaticvoid main(String[] args){

Exercise32_6 applet =new Exercise32_6();

JFrame frame =new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setTitle("Exercise32_6");

frame.getContentPane().add(applet, BorderLayout.CENTER);

applet.init();

applet.start();

frame.setSize(380, 180);

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

}

[5625 byte] By [james-mcfaddena] at [2007-11-27 11:33:15]
# 1

The answer to your question is "replace the text JComboBox with JCheckBox". But that's not the answer to your problem. What is your problem? Checkboxes and combo boxes aren't similar enough to be interchangeable, so what are you trying to do?

This really belongs in the swing forum, btw

georgemca at 2007-7-29 16:50:14 > top of Java-index,Java Essentials,Java Programming...
# 2

hello.

thanks for the reply. i want users of my video library system to be able to view CD/DVD/Game information by name, age category, type and year. Users should be able to click on a check box (e.g. view by name, age category, type or year) and press a button. What would happen then is that data from the Product table would appear in the text area.

james-mcfaddena at 2007-7-29 16:50:14 > top of Java-index,Java Essentials,Java Programming...
# 3

Quit triple posting your questions. This is a Swing related question and only needs to be posted in the Swing forum.

camickra at 2007-7-29 16:50:14 > top of Java-index,Java Essentials,Java Programming...