To find out how to remove and update 1 line from jettbables, find out the following code of
Use:
DefaultTableModel modelTable = (DefaultTableModel) jTabelRooster.getModel (); ModelTable.addRow (new object [] {lid.getLidnummer (). ToString (), lid.getLidvoornaam (), lid.getLidtussenvoegsel (), lid.getLidachternaam (), lid.getAanwezig ()}); Ok so far so good .. the rows are added well ... but now I would like to remove them:
int selectedRow = jTabelRooster .getSelectedRow (); ModelTable.removeRow (SelectedRow); When I did not get this I received the following error: Exception in the formula "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2> = 2 Your help will be appreciated
EDIT: Jetelblaster has been inserted by GUI layout manager, so now I have this code, and more to me Success was not found:
Private zero initRoosterDetail () {for (int i = 0; i & lt; leden.size (); i ++) {lid = leden.get (i) ; ModelTable.addRow (new object [] {lid.getLidnummer (). ToString (), lid.getLidvoornaam (), lid.getLidtussenvoegsel (), lid.getLidachternaam (), lid.getAanwezig ()}); }} Private Zero jbInschrijvingVerwijderenActionPerformed (java.awt.event.ActionEvent evt) {int SelectedRow = jTabelRooster.getSelectedRow (); ModelTable.removeRow (jTabelRooster.convertRowIndexToModel (SelectedRow)); } this should be :)
When I select 1 row in the table and press Cancel button. I get this message:
> Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2> = 2 ================================== ================================================== ================================================== ================================================== ================================================== ================================================== =========================================== All Thanx for help ... I know ... what to do with it was a table model listener I used to do wrong .. So this has left me with another problem :)
jTabelRooster.getModel (). AddTableModelListener (New TableModelListener) {Public Zero Table Changed (TableModelEvent evt) {if (jTabelRooster GetSelectedColumn () == 4) {}}}); This code was messing up the deleterow command.
I have 1 boolean column that has a checkbox in it: (
Integrated selectedRow = jTabelRooster.getSelectedRow (); modelTable.removeRow (selectedRow); > If there is a row, then the former jTabelRooster.getSelectedRow () again -1
before you remove the check if the row is selected.
int selectedRow = jTabelRooster. GetSelectedRow (); if (selectedRow! = -1) {modelTable.removeRow (selectedRow);} PS: Java naming conventions follow Try it.
Edit: An example that shows how to add and delete rows by using DefaultTableModel from a table. / P> Private Zero createUI () {JFrame frame = new JFrame (); frame.Setlightout (new border layout ()); Last JTable table = new JTable (); Final DefaultTableModel model = New D EfaultTableModel (5, 3); Table.setModel (model); Jpnl btnpnl = new jpn (new border layout ()); Zeppel BottomNPNL = New Zipel (New Flow Layout (Flow Layouts.c.A.)); Pocket button addBtn = new pocket ("add"); JButton deleteBtn = new pocket ("remove"); BottombtnPnl.add (addBtn); BottombtnPnl.add (deleteBtn); AddBtn.addActionListener (New Executionist) {@Override Public Zero Action Performance (ActionEvent e) {model.addRow (new object [] {}}}}}}); DeleteBtn.addActionListener (New Executionist) {@Override Public Null Transform (ActionEvent) {int selRow = table.getSelectedRow (); if (selRow! = -1) {model.removeRow (selRow);}}}); BTNPNL.ed (Bottlebutton PNL, Border Layout. CA); . Table.getTableHeader () setReorderingAllowed (incorrect); Frame.add (table.getTableHeader (), border layout.NORTH); Frame.add (Table, Border Layout. CA); Frame.ed (BTNPNL, border layout.SOHT); Frame.setTitle ("JTable Example."); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.pack (); Frame.setVisible (true); }
No comments:
Post a Comment