jtable: add empty row and delete row with values

i'm having a headache trying to add a new row as well as to delete row into my jtable.
here's part of my codes...(some of it are deleted bcos not relevant and to conserve space)

SalesApp.java
----------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.table.*;

public class SalesApp extends JPanel {

      String rand;
      
  JButton New = new JButton(); //the button to add row
  JButton Edit = new JButton();
  JButton Cancel = new JButton(); //the button to delete row
  JButton Enter = new JButton();
  JButton Search = new JButton();
 
  NewTableModel model=new NewTableModel();
  JTable Table=new JTable(model);
 
  public SalesApp() {
    try {
      jbInit();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }
  void jbInit() throws Exception {
    this.setSize(800,348);
    this.setBackground(Color.white);
    this.setLayout(borderLayout1);
    this.add(SalesTop,  BorderLayout.CENTER);
    this.add(SalesMenu,  BorderLayout.SOUTH);
   
    New.setText("New");
    New.setBounds(new Rectangle(8, 7, 76, 21));
    New.addActionListener(new SalesButton(this));
    Edit.setText("Edit");
    Edit.setBounds(new Rectangle(89, 7, 76, 21));
    Edit.addActionListener(new SalesButton(this));
    Cancel.setText("Cancel");
    Cancel.setBounds(new Rectangle(283, 7, 76, 21));
    Cancel.addActionListener(new SalesButton(this));
    Enter.setText("Enter");
    Enter.setBounds(new Rectangle(201, 7, 76, 21));
    Enter.addActionListener(new SalesButton(this));

    Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    Table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    TableColumn column = null;
    for (int i = 0; i < 7; i++) {
    column = Table.getColumnModel().getColumn(i);
    if (i == 0)
            column.setPreferredWidth(50);
    else
            column.setPreferredWidth(120);
      }
  }

      class NewTableModel extends AbstractTableModel
      {
            String [] columnNames = {"No","Product ID",
            "Description","Quantity","Discount",
            "Price ( Per Unit )", "Amount"};
      
            Object[][] data = {
                  {"1","apara","stupid stuff","2","20","300","480"},
                  {"","","","","","",""},                        
                  };

            public int getRowCount()
            {
                  return data.length;
            }
            
            public int getColumnCount()
            {
                  return columnNames.length;
            }
            
            public String getColumnName(int col)
            {
                  return columnNames[col];
            }
            
            public Object getValueAt(int row, int col)
            {
                  return data[row][col];
            }
            
            public void setValueAt(Object value, int row, int col)
            {
                  data[row][col]=value;
                  fireTableCellUpdated(row,col);
            }
      }
      
      public String randomize()
      {
            return String.valueOf((int)(Math.random()*100000));
      }
}
----------------------------------------------------------------------------

SalesButton.java
----------------------------------------------------------------------------
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class SalesButton extends DBConnector implements ActionListener, ListSelectionListener
{
      private SalesApp sa;
      TableModel model;
      static int selectedRow;
      
      public SalesButton(SalesApp s1)
      {
            sa=s1;
      }
      
      public void actionPerformed(ActionEvent e)
      {
            if (e.getSource()==sa.New)
            {
                  try //here's where i try to add a new row
                  {
                  }

                  catch(Exception err)
                  {
                        System.out.println("Error: "+ err);
                  }
            }
            
            if (e.getSource()==sa.Cancel)
            {
                  try //here's where i try to delete a row
                  {
                  }

                  catch(Exception err)
                  {
                        System.out.println("Error: "+ err);
                  }
            }
      }
----------------------------------------------------------------------------

how do i do it?? i can't use another table model bcos i already have abstracttablemodel. thanx

gildan2020
gildan2020Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You'd save yourself a lot of trouble and work if you ditched your table model and just *used* a DefaultTableModel. This supports addition and deletion of rows out of the box.
0
gildan2020Author Commented:
unfortunately, i wish i could...
is there any codes that add and delete row for AbstractTableModel?? plz gimme the sample codes that might work with my current codes

thanx

gildan2020
0
CEHJCommented:
The best thing would be to look at the source code for DefaultTableModel. Failing that:

Use a collection for your data - not an array. The latter is inherently static. A vector of vectors would be a good idea as this is standard.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

gildan2020Author Commented:
can u give me some sample codes that are based on AbstractTableModel?

gildan2020
0
gildan2020Author Commented:
hey, i'm proposing to delete dis question since there hasn't been any post for nearly two weeks

if u hav any objections...plz do comment thanx

(on de instructions of the moderator, SpideyMod)
gildan2020
0
SpideyModCommented:
PAQ'd and points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gildan2020Author Commented:
thanx spideymod

gildan2020
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.