hi, im new to java and im having problems with getting the selected checkbox in a jtable cell....i want to get the values of the selected one and store it into an array...could anybody help me how? tnx....
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hi, im new to java and im having problems with getting the selected checkbox in a jtable cell....i want to get the values of the selected one and store it into an array...could anybody help me how? tnx....
You're going to have to be a lot more specific. Try creating an SSCCE (that's a link) that demonstrates your problem. Don't forget the code tags.
repryd (December 23rd, 2010)
my problem is that i want to get the checked values of the checkboxes whenever the save button is being pressed...
empmodel.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { int rindex1=jTable1.getSelectedRow(); String selvalue1=jTable1.getValueAt(rindex1,1).toString(); String selvalue2=getShiftIdFromShiftDesc(shifts.getSelectedItem().toString()).elementAt(0).toString(); String sel=jTable1.getValueAt(rindex1,0).toString(); try { if(sel.equals("true")) { new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}"); new ConnectDB().create("{CALL payroll._assignInsertShift('" + selvalue1 + "','" + selvalue2 + "',null,null)}"); } else { new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}"); } } catch(Exception ex) { ex.printStackTrace(); } } }); } catch(Exception ex) { ex.printStackTrace(); }
That is not an SSCCE, and you did not use the code tags. Without seeing an SSCCE or understanding what you mean, I can only point you to the JTable API: JTable (Java Platform SE 6)
Hello and welcome to the forums. Please post something we can compile.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
empmodel.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { int rindex1=jTable1.getSelectedRow(); String selvalue1=jTable1.getValueAt(rindex1,1).toString(); String selvalue2=getShiftIdFromShiftDesc(shifts.getSelectedItem().toString()).elementAt(0).toString(); String sel=jTable1.getValueAt(rindex1,0).toString(); try { if(sel.equals("true")) { new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}"); new ConnectDB().create("{CALL payroll._assignInsertShift('" + selvalue1 + "','" + selvalue2 + "',null,null)}"); } else { new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}"); } } catch(Exception ex) { ex.printStackTrace(); } } }); } catch(Exception ex) { ex.printStackTrace(); }
can you show me how to store selected checkbox values into an array...?
for example:
in a jtable where the first column contains checkboxes in which you need to check or uncheck...
i jst want to retrieve that unchecked or checked values being triggered....storing it into an array....
i mean the true or false values....
The code you provided doesn't really help us answer your question. Did you take a look at the JTable API? There are methods for getting the values stored in the JTable. You might also check out TableModel for the same types of methods.