swing - accessing vector inside a vector in Java -
I have populated jTable from a database, now I want to add more functionality, I want to delete a line, my My data structure is near:
public vector getUser () throws exception {vector & lt; Vector & lt; String & gt; & Gt; User vector = new vector & lt; Vector & lt; String & gt; & Gt; (); Class.forName ("com.mysql.jdbc.Driver"); Conn = DriverManager.getConnection (DB_URL, USER, PASS); Prepared place pre = conn.prepareStatement ("Select * away from"); Rs = pre.executeQuery (); While (rsnext ()) {vector & lt; String & gt; User = new vector & lt; String & gt; (); User.add (rs.getString (1)); user.add (rs.getString (2)); user.add (rs.getString (3)); user.add (rs.getString (4)); userVector.add (user); } If (conn! = Null) conn.close (); User vector return; } Next I made jTable with the model like this
jTable1.setModel (new javax.swing.table.DefaultTableModel (data, header)) ; So now I want to delete the row using jTable1.remove (int)
; There are 7 rows in my DB and when I put int = 1 IfBoundsException: 1
I get it wrong, okay? How do I remove a line properly?
To delete a row from the table, you want
( (DefaultTableModel) jTable.getModel ()). Remove (line tromovov); JTable is actually some performance logic: it controls the data model, and that there is a table model below the need to interact with you . Then the table itself will be present in the table model. Since you are creating DefaultTableModel , the easiest way to achieve this is to set the model through the medium default table model Model = new DefaultTableModel (data, header); JTable1.setModel (model); and then later
models .removeRow (rowToRemove); Every time you inquire from the table to find the table model.
शौकीनों के लिए जावा कंप्यूटर प्रोग्रामिंग कोड
ReplyDeleteकमांड लाइन कोड नमूने से पासवर्ड छिपाएं