am creating an analysis system using JFreechart Library and I want to have something like pivot table functionalities like the one in MS excel, I want to Pool a certain database field so that I have Jcheckboxes having the names of each distinct value from the database. I have implemented this using JCombobox like:
Class.forName("oracle.jdbc.driver.OracleDriver");
dbcon = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "USERNAME", "PASSWORD");
Statement st = dbcon.createStatement();
String combo = "Select DORM_NAME from dormitory_master_table";
ResultSet res = st.executeQuery(combo);
Vector v = new Vector();
while (res.next()) {
String ids = res.getString("DORM_NAME");
v.add(ids);
cboDormitory = new JComboBox(v);
This gets all dorm name into the Jcombobox, but this is ineffective for what I want to do as I need to be able to select multiple objects. How Can i implement this?
to clarify do you want multiple
JCheckBoxs in a singleJComboBoxin order to allow multiple selection without having hundreds ofJCheckboxs on screen?Sounds like work for
JListin this case.see:
A
JListwill allow multiple selection from a list of values (screenshot taken straight from orcale – How to Use Lists tutorial to illustrate what I mean):Here is a custom example I had which uses
JCheckBoxs:UPDATE
as per your comment:
1) Replace:
Vector v = new Vector();withArrayList<String> v=new ArrayList<>();2) Now edit
createData(..)to resemble:3) Simply call the
createDatawith reference toArrayList(which we calledv):