Relating text fields to check boxes in Java
- by Finzz
This program requires the user to login and request a database to access. The program then gets a connection object, searches through the database storing the column names into a vector for later use. The problem comes with implementing text fields to allow the user to search for specific values within the database.
I can get the check boxes and text fields to appear using a gridlayout and add them to a panel. How do I relate the text fields to their appropriate check box?
I've tried adding them to a vector, but then they can't also be added to the panel as well. I've searched for a way to name the text fields as the loop cycles through the column names, but it seems impossible to do without having them declared ahead of time. This can't be done either, as it's impossible to determine the attributes that the user will request.
I just need to be able to know the names of the text fields so I can test to see if the user entered information and perform the necessary logic. Let me know if you have to see the rest of the code to give an answer, but hopefully you get the general idea of what I'm trying to accomplish.
Picture of UI:
try {
ResultSet r2 = con.getMetaData().getColumns("", "", rb.getText(), "");
colNames1 = new Vector<String>();
columns1 = new Vector<JCheckBox>();
while (r2.next()) {
colNames1.add(r2.getString(4));
JCheckBox cb = new JCheckBox(r2.getString(4));
JTextField tf = new JTextField(10);
columns1.add(cb);
p3.add(cb);
p3.add(tf);
}
}