See new row in JTable

Hi
I haven't found this one yet:
How to see new row in an already visible JTable after ((DefaultTableModel)JTable.getModel()).setRowCount(x + 1...n) or any other statement (...addRow(...), insertRow(....), ...?) ?
(Using J2SE 1.5(beta) on Win XP)
Any help very appreciated!

Use a DefaultTableModel. Then call model.addRow(), etc and the table will update.
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;
public class TableRowAdderTest extends JFrame{
    private DefaultTableModel model;
    public TableRowAdderTest() {
        buildGUI();
    private void buildGUI() {
        JPanel mainPanel = (JPanel) getContentPane();
        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(buildTablePanel(),BorderLayout.CENTER);
        mainPanel.add(buildButtonPanel(), BorderLayout.SOUTH);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        setVisible(true);
    private JPanel buildButtonPanel() {
        JPanel retPanel = new JPanel();
        JButton addButton = new JButton("Add");
        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addRow();
        retPanel.add(addButton);
        return retPanel;
    private void addRow() {
        Vector rowVector = new Vector();
        rowVector.add("data 1");
        rowVector.add("data 2");
        rowVector.add("data 3");
        model.addRow(rowVector);
    private JPanel buildTablePanel() {
        JPanel retPanel = new JPanel();
        model = new DefaultTableModel();
        model.setColumnIdentifiers(new String[]{"Column 1","Column 2", "Column 3"});
        JTable table = new JTable(model);
        JScrollPane jsp = new JScrollPane(table);
        retPanel.add(jsp);
        return retPanel;
    public static void main(String[] args) {
        new TableRowAdderTest();
}This same approach will work for inserting rows, altering cell values, etc.
Cheers
DB

Similar Messages

  • Problem with adding a new row in JTable

    Hi,
    I've created a JTable using DefaultTableModel with DefaultTableModel(Object[][] obj,Object[] col) constructor.I've written actionListener for a JButton which should add new row to the tablemodel.Now, the listener adds the row to the model.But its throwing an ArrayOutofBoundsException and the added row is not visible unless I click on any column of the table.
    Kindly help me to resolve this problem
    TIA
    Regards
    Gopi

    Thanks a lot for the reply. Here is the complete code
    TableImpl.java
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import java.util.Vector;
    public class TableImpl extends JFrame {
    DefaultTableModel dataModel;     // TableModel Variable
    /* Constructor to add table and button to the frame     */
    TableImpl() {
              getContentPane().setLayout(null);
              setSize(800,600);
              myModel();
              final JTable table = new JTable(dataModel);
              JScrollPane scrollpane = new JScrollPane(table);
              getContentPane().add(scrollpane);
              scrollpane.setBounds(10,10,700,300);
              TableColumn tcCol = table.getColumnModel().getColumn(1);
              /* Adding ComboBox to the CellEditor of Column 2 of table     */
              JComboBox jcbComboBox = new JComboBox();
              final ReturnVector vctDBAccess = new ReturnVector();
              jcbComboBox.addItem(vctDBAccess.vctGetOidList().elementAt(0).toString());
              jcbComboBox.addItem(vctDBAccess.vctGetOidList().elementAt(2).toString());
              jcbComboBox.addItem(vctDBAccess.vctGetOidList().elementAt(4).toString());
              tcCol.setCellEditor(new DefaultCellEditor(jcbComboBox));
              /*     Adding Listener for Table      */
              dataModel.addTableModelListener(new TableModelListener() {
                   public void tableChanged(TableModelEvent e) {
              /* Columns Manipulation */
                        if(dataModel.getColumnName(e.getColumn()).equals("Second")) {
                        int iRow = e.getFirstRow();
                        int iColumn = e.getColumn();
                        String strColName = dataModel.getColumnName(iColumn);
                        String strData = (String)dataModel.getValueAt(iRow,iColumn);
                        String strNextColumn = dataModel.getColumnName(iColumn+1);
                        dataModel.setValueAt(vctDBAccess.vctGetOidList().elementAt(vctDBAccess.iGetIndex(strData)+1),iRow,iColumn+1);
              /* Adding button to Frame     */
              JButton jbInsert = new JButton("Insert");
              /* Adding new row to the Tablemodel -- Probelm is here     */
              jbInsert.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e){
                        try {
                   Object[] nrow = {"what", "ever", "you"};
                   dataModel.addRow(nrow);
                   }catch(Exception ex) {
                   System.out.println("Exception at adding row = " + ex);
    getContentPane().add(jbInsert);
    jbInsert.setBounds(100,350,100,20);
    addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
                   System.exit(0);
         /* Method to initialise new tablemodel     */
         public void myModel() {
              Object[][] data = { {new Integer(10),"two","three"},
                                                 {new Integer(5),"two","three"},
                                                 {new Integer(4),"two","three"},
              String[] col = { "First", "Second", "Third"};
              dataModel = new DefaultTableModel(data,col);
    public static void main(String arg[]) {
              TableImpl ct = new TableImpl();
              ct.setVisible(true);
    /* Class that returns a Vector of String for populating ComboBox entries and
              for getting the index of a particular element of the vector          */
    class ReturnVector {
                   Vector vctOidName=null;
                   ReturnVector() {
                        this.vctOidName = new Vector();
                        vAddOidList();
                   public void vAddOidList() {
                        String[] dbResult = {      "system", "1.3.6.1.2.1.1" ,
                                                      "interface", "1.3.6.1.2.1.2" ,
                                                      "snmp", "1.3.6.1.2.1.3" };
                        for(int i=0;i<dbResult.length;i++) {
                             System.out.println("Value = " + dbResult);
                             vctOidName.addElement(dbResult[i]);
                   public Vector vctGetOidList() {
                        return vctOidName;
                   public int iGetIndex(String strData) {
                        System.out.println("Index = " + vctOidName.indexOf(strData));
                        return vctOidName.indexOf(strData);

  • How to insert new row in JTable?

    In my application,I have a jTable. And the form dose not have a Nevigation bar.
    After I retrieve a record into the jTable, I want to add a new row after the retrieved record. But I could not create a new row by pressing the down key at the last row of the jTable(I could do that in Oracle Form). Dose jTabel have such feature as that in Oracle Form? Or I can do that in another way?

    Such a feature is not available, but you could add a key event handler which works its magic when it detects a press on the down arrow key, while the last row is selected. Then you can perform the code to insert a new row.

  • New row in JTable

    Hey!
    I have a pretty stupid question... How can I add a new row in a JTable?
    Thanks,
    Edgar

    Hi,
    it depends on the TableModel you are using - if your JTable uses a DefaultTableModel you will find the methods to add a row in the DefaultTableModel class - they are named addRow(...) and easy to find in the documentation of this class - you can get this table model from your JTable using ...
    DefaultTableModel model = (DefaultTableModel) yourJTable.getModel();
    if your JTable does not use a DefaultTableModel, you will get a ClassCastException by this line.
    greetings Marsian

  • JSP can't see new row without manual browser reload

    I use two JSP files in a JDev 3.1 "application."
    In the first JSP, I first use a RowSetBrowser to display the contents of the table EMP. I next use the setFormAction of an EditForm in this first JSP to "jump" to the second JSP file. In the second JSP, I insert a new row into EMP. Still in the second JSP, I then use <jsp:forward page="first.jsp" /> to return to the first page. But, upon returning to the first JSP, the new row cannot be seen in the resulting HTML page until I reload the page manually.
    What can I do programmatically to have the first JSP page show the new row the second time the first JSP produces a HTML?

    Thanks for these tips.
    Could you go to the next step and provide snippets of code to flesh out these two approaches?
    1. How does one write the header in the 1st page?
    2. How does one create the a_unique_timestamp in this situation?
    Thanks for any further help that you can provide!
    null

  • Dynamically adding a new row to a JTable

    Have anybody tried to add a new row to JTable? In the JTable if the user is editing the last row, another row should be created and displayed dynamically, without loosing the contents in the other rows and without any flickering effect. Is this possible in java applications or applets?
    -Madhuri.

    again, do all yoru work in the table model. make a class that implements the table model interface. if you mail me I can send you a table model I made(I have about 8) and you will see what to do from that. Its all about the table Model, not the table.
    Try using ArrayList instead of Vector unless you need it to be thread safe.

  • JTable checkboxes doesn't retain their selection when a new row is added!!

    HI,
    My gui has the JTable component which has 5 columns. out of which 4 columns are checkboxes. whenever i select an item from the Jlist and click on the add button it will add a new row in JTable.
    but the problem is whenever a new row is added to the table. the previously selected checkboxes of previous rows are being deselected. But i want to retain the selection of my previous rows even when a new row is added. please help me how to achieve this..i am posting my JTable code here:
    class FunctionTableModel extends AbstractTableModel{
           /** The instances who's attribute structure we are reporting */
        //protected InitModel m_init;
        protected String func_element;
        protected int counter;
        //protected String[] func_array;
        protected Vector func_vector;
        /** The flag for whether the instance will be included */
        protected boolean [] m_Sum;
        protected boolean [] m_Min;
        protected boolean [] m_Avg;
        protected boolean [] m_Max;
        protected boolean [] m_SD;
         * Creates the tablemodel with the given set of instances.
         * @param instances the initial set of Instances
        public FunctionTableModel() {
          counter =0;
             func_vector = new Vector();
         public FunctionTableModel(Vector vec) {
            func_vector = vec;
        public Vector getDataVector(){
            return func_vector;
         * Sets the tablemodel to look at a new set of instances.
         * @param instances the new set of Instances.
        public void setElement(Vector vec) {
               for(int i=0;i<vec.size();i++){
            func_vector.add(vec.elementAt(i));
            counter++;
          fireTableDataChanged();   
          m_Sum = new boolean [counter];
          m_Min = new boolean[counter];
          m_Avg = new boolean[counter];
          m_Max = new boolean[counter];
          m_SD = new boolean[counter];
         * Gets the number of attributes.
         * @return the number of attributes.
        public int getRowCount() {
               return func_vector.size();
         * Gets the number of columns: 3
         * @return 3
        public int getColumnCount() {
          return 6;
         * Gets a table cell
         * @param row the row index
         * @param column the column index
         * @return the value at row, column
        public Object getValueAt(int row, int column) {
          switch (column) {
          case 0:
            return func_vector.elementAt(row);
          case 1:
            return new Boolean(m_Sum[row]);
          case 2:
            return new Boolean(m_Min[row]);
          case 3:
            return new Boolean(m_Avg[row]);
          case 4:
            return new Boolean(m_Max[row]);
          case 5:
            return new Boolean(m_SD[row]); 
          default:
            return null;
        public void removeAll(){
            func_vector.removeAllElements();
            fireTableDataChanged();
         * Gets the name for a column.
         * @param column the column index.
         * @return the name of the column.
        public String getColumnName(int column) {
          switch (column) {
          case 0:
            return new String("Function Selected");
          case 1:
            return new String("Sum");
          case 2:
            return new String("Min");
          case 3:
            return new String("Avg");
          case 4:
            return new String("Max");
          case 5:
            return new String("SD");   
          default:
         return null;
         * Sets the value at a cell.
         * @param value the new value.
         * @param row the row index.
         * @param col the column index.
        public void setValueAt(Object value, int row, int col) {
          if(col == 0){
            counter++;
            func_vector.add(counter,value.toString());
          if (col == 1)
            m_Sum[row] = ((Boolean) value).booleanValue();
          if (col == 2)
            m_Min[row] = ((Boolean) value).booleanValue();
          if (col == 3)
            m_Avg[row] = ((Boolean) value).booleanValue();
          if (col == 4)
            m_Max[row] = ((Boolean) value).booleanValue();
          if (col == 5)
            m_SD[row] = ((Boolean) value).booleanValue();       
         * Gets the class of elements in a column.
         * @param col the column index.
         * @return the class of elements in the column.
        public Class getColumnClass(int col) {
             return getValueAt(0, col).getClass();
         * Returns true if the column is the "selected" column.
         * @param row ignored
         * @param col the column index.
         * @return true if col == 1.
        public boolean isCellEditable(int row, int col) {
          if (col >= 1) {
             return true;
          return false;
        public void removeRow(int row){
            if(row<=func_vector.size()){
                          func_vector.removeElementAt(row);
                counter--;
            fireTableDataChanged();
        }

    hi parvathi,
    i have made changes to my previous code and here's the code:
      class FunctionTableModel extends DefaultTableModel{
           /** The instances who's attribute structure we are reporting */
        //protected InitModel m_init;
        protected String func_element;
        protected int counter;
        protected int counter1;
        //protected String[] func_array;
        protected Vector func_vector;
        /** The flag for whether the instance will be included */
        protected boolean [] m_Sum;
        protected boolean [] m_Min;
        protected boolean [] m_Avg;
        protected boolean [] m_Max;
        protected boolean [] m_SD;
        //protected Vector m_Sum1;
        //protected Vector m_Min1;
        //protected Vector m_Avg1;
        //protected Vector m_Max1;
        //protected Vector m_SD1;
         * Creates the tablemodel with the given set of instances.
         * @param instances the initial set of Instances
        public FunctionTableModel() {
            System.out.println("entered the constr");
          counter =0;
          //counter1=0;
          //m_Sum1 = new Vector();
          //m_Min1 = new Vector();
          //m_Avg1 = new Vector();
          //m_Max1 = new Vector();
          //m_SD1 = new Vector();
          //func_array = new String[];
          func_vector = new Vector();
         public FunctionTableModel(Vector vec) {
            func_vector = vec;
            //setElement(func_vector);
        public Vector getDataVector(){
            return func_vector;
         * Sets the tablemodel to look at a new set of instances.
         * @param instances the new set of Instances.
        public void addRow(Vector vec) {
          //counter++; 
          //func_element = ele;
          //System.out.println("FunctionTableModel- setElement() method");
          for(int i=0;i<vec.size();i++){
            func_vector.add(vec.elementAt(i));
            counter++;  
           //System.out.println("counter ="+counter+new boolean[counter]); 
            //m_Sum1 = m_Sum;
            //m_Min1 = m_Min;
            //m_Avg1 = m_Avg;
            //m_Max1 = m_Max;
            //m_SD1 = m_SD;
            //m_Sum = new boolean[counter];
            //System.out.println("at setElement");
            m_Sum = new boolean[counter];
            //System.out.println(counter);
            m_Min = new boolean[counter];
            //m_Min;
            m_Avg = new boolean[counter];
            //m_Avg1 = m_Avg;
            m_Max = new boolean[counter];
            //m_Max1 = m_Max;
            m_SD = new boolean[counter];
            //m_SD1 = m_SD;
            //counter1++;
          //func_array[counter]=ele;
          //func_vector.add(counter,ele);
          fireTableDataChanged();  
         * Gets the number of attributes.
         * @return the number of attributes.
        //public int getRowCount() {
          //System.out.println("FunctionTableModel- getRowCount() method");
          //return func_vector.size();
         * Gets the number of columns: 3
         * @return 3
        public int getColumnCount() {
          return 6;
         * Gets a table cell
         * @param row the row index
         * @param column the column index
         * @return the value at row, column
        public Object getValueAt(int row, int column) {
          switch (column) {
          case 0:
            return func_vector.elementAt(row);
          case 1:{
            //System.out.println("in case 1");
            //Boolean m_Sum_Value = new Boolean(m_Sum[row]);
            //System.out.println("m_Sum_Value:"+m_Sum_Value.booleanValue());
            return new Boolean(m_Sum[row]);
            //m_Sum1.add(m_Sum_Value);
            //return m_Sum_Value;
          case 2:
            return new Boolean(m_Min[row]);
          case 3:
            return new Boolean(m_Avg[row]);
          case 4:
            return new Boolean(m_Max[row]);
          case 5:
            return new Boolean(m_SD[row]); 
          default:
            return null;
        public void removeAll(){
            func_vector.removeAllElements();
            //m_Sum1.removeAllElements();
            fireTableDataChanged();
         * Gets the name for a column.
         * @param column the column index.
         * @return the name of the column.
        public String getColumnName(int column) {
          switch (column) {
          case 0:
            return new String("Function Selected");
          case 1:
            return new String("Sum");
          case 2:
            return new String("Min");
          case 3:
            return new String("Avg");
          case 4:
            return new String("Max");
          case 5:
            return new String("SD");   
          default:
         return null;
         * Sets the value at a cell.
         * @param value the new value.
         * @param row the row index.
         * @param col the column index.
        public void setValueAt(Object value, int row, int col) {
          if(col == 0){
            counter++;
            func_vector.add(counter,value.toString());
          if (col == 1) {
            m_Sum[row] = ((Boolean) value).booleanValue();
            //System.out.println("m_Sum length "+m_Sum.length);
            //for(int i=0;i<=row;i++)
            //    System.out.println("m_Sum1 "+i+((Boolean)m_Sum1.elementAt(i)).booleanValue());
            //System.out.println("m_Sum1["+row+"] "+ ((Boolean)m_Sum1.elementAt(row)).booleanValue());
            //    System.out.println("m_Sum["+i+"] "+ m_Sum);
    if (col == 2)
    m_Min[row] = ((Boolean) value).booleanValue();
    if (col == 3)
    m_Avg[row] = ((Boolean) value).booleanValue();
    if (col == 4)
    m_Max[row] = ((Boolean) value).booleanValue();
    if (col == 5)
    m_SD[row] = ((Boolean) value).booleanValue();
    * Gets the class of elements in a column.
    * @param col the column index.
    * @return the class of elements in the column.
    public Class getColumnClass(int col) {
    return getValueAt(0, col).getClass();
    * Returns true if the column is the "selected" column.
    * @param row ignored
    * @param col the column index.
    * @return true if col == 1.
    public boolean isCellEditable(int row, int col) {
    if (col >= 1) {
         return true;
    return false;
    public void removeRow(int row){
    if(row<=func_vector.size()){
    func_vector.removeElementAt(row);
    counter--;
    fireTableDataChanged();
    previouslu i was using the setElement method. now i have replaced with the addRow method...
    but anyways...the control is not going to any of these overridden methods...and none of the elements are added to the table. But i comment of all the addRow, getValueAt, getColumnClass methods...then it's adding rows to the table but with only the first column all the remaiing columns are just empty...
    i am fed up with this...if you observe i have commented out somany lines...becoz i am trying to save my boolean array values into a vector..but that was also in vain...
    i appreciate for ur help...
    thanks
    sri

  • New Row gets created in table automatically

    Hi all,
    I have a panel box(pb1) in my JSFF which has a table(tbl1).
    When the table is empty, if i collapse table's parent panel box i.e. pb1,
    n again expand it..,I see new row created in the table...
    I haven't put any code to create new blank row in table view object on collapse n expand of panel box...
    How to fix this issue..?
    JDEV vesion : 11.1.1.4.0
    Please reply...
    Thanks.

    Hi yaminip,
    Its not necessary to put the code in expand and collapse action of the panel box may it can be in different place
    and the table may refersh while u expand /collapse the panel box and new row came to visible.... keep break point in the EntityImpl Create method or ViewObjectImpl InsertRow method
    Find when its get fired........
    Regards,
    Suganth.G

  • How can I add a new row in a JTable dynamically?

    Dear Sir(s)
    I want to add a new row in a Jtable as I press enter key the time focus is on the last cell of the row? pls help

    TomDooley wrote:
    Hello,
    ...I write directly to a cvs file ...my loop slows down to 0.2 Hz
    Writing a series of 5 values to a file should not take so long. There is probably something wrong in the way you are saving your data. May be you should post a simplified version of your vi, so we could see how to improve your code.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Creating a new row in a JTable

    How do i make a new row in a JTabel?

    is there a line something like: newRow(); but anyway here is the code i have so far thanx for the help:
    class UserSettings extends JFrame implements ActionListener {
      private JMenuBar menu = new JMenuBar();
      private JMenu Settings;
      private JMenuItem exit;
      private JButton sset;
      String[] columnNames = {"users","passwords"};
      Vector dat = new Vector();
      private JTable usertable;
      public UserSettings() {
        setSize(new Dimension(350, 350));
        setTitle("User Setings");
        Settings = new JMenu("Settings");
        menu.add(Settings);
        exit = new JMenuItem("Exit");
        exit.addActionListener(this);
        Settings.add(exit);
        sset = new JButton("Save settings");
        sset.addActionListener(this);
        try {
          BufferedReader userin = new BufferedReader(new FileReader("users/userp.txt"));
          String su;
          while ((su = userin.readLine()) != null) {
            String[] uspa = su.split(" ");
            dat.add(uspa);
        catch (FileNotFoundException ioe) {
          JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);
        catch (ClassCastException ioe){}
        catch (NullPointerException ioe) {}
        catch (IOException ioe) {
          JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);
        String[][] data = new String[dat.size()][];
        for(int x = 0; x < dat.size(); x++) {
          data[x] = (String[])dat.get(x);
        usertable = new JTable(data, columnNames);
        JScrollPane scrollpane = new JScrollPane(usertable);
        usertable.setPreferredScrollableViewportSize(new Dimension(50, 500));
        JPanel pane = new JPanel(new GridLayout(0, 1));
        getContentPane().add(scrollpane);
        getContentPane().add(sset, BorderLayout.SOUTH);
        setJMenuBar(menu);
      public void actionPerformed(ActionEvent e) {
        if (e.getSource() == sset) {
             int count = usertable.getRowCount();
             if (count == 1) {
             if (count == 2) {
             if (count == 3) {
          try {
               FileWriter uname = new FileWriter("users/usertest.txt");
               String sname;
               uname.write("test");
               uname.close();
          catch (IOException ioe) {
               JOptionPane.showMessageDialog(null, "Error saving you file, if error persists contact [email protected] or reenstal", "", JOptionPane.WARNING_MESSAGE);
          dispose();
        if (e.getSource() == exit) {
          int exitask = JOptionPane.showConfirmDialog(UserSettings.this, "Are you sure you want to exit? Any unsaved settinging changes will be lost!!");
          if (exitask == JOptionPane.YES_OPTION) {
            dispose();
    Thanx again

  • Trying to add a new row to a JTable

    I'm having trouble adding a row dynamically to a JTable. I've been able to populate the table with an array and that works well, but how do you add new rows after the program is running?

    You need to make TableModel that does dynamic resizing od the underlying data 2d array. This one will resize for both rows and columns.
        private Vector dataNames= new Vector();
        private Vector dataData =new Vector();
            javax.swing.table.TableModel dataModel = new javax.swing.table.AbstractTableModel()
                public int getColumnCount()
                    return dataNames.size();
                public int getRowCount()
                    return dataData.size();
                public Object getValueAt(int row, int col)
                    try
                        java.util.Vector v=(java.util.Vector)dataData.elementAt(row);
                        return v.elementAt(col);
                    catch(Exception e)
                        System.out.println("e :"+e.getMessage());
                        return null;
                public String getColumnName(int column)
                    return (String)dataNames.elementAt(column);
                public Class getColumnClass(int col)
                    if(getValueAt(0,col)!=null)
                        return getValueAt(0,col).getClass();
                    else
                        if(col==0)
                            return Integer.class;
                        else if(col==1 || col==2)
                            return Double.class;
                        else
                            return String.class;
                public boolean isCellEditable(int row, int col)
                    if(col > 0 && col <4)
                        return mapTableEditable;
                    else
                        return false;
                public void setValueAt(Object aValue, int row, int column)
                    if(row>=dataData.size())
                        if(dataData.size()==0)
                            for(int i=0;i<row+1;i++)
                                dataData.addElement(new java.util.Vector());
                                java.util.Vector v2=(java.util.Vector)dataData.lastElement();
                                v2.setSize(getColumnCount());
                        else
                            java.util.Vector v1=(java.util.Vector)dataData.lastElement();
                            int dataSize=row-dataData.size()+1;
                            for(int i=0;i<dataSize;i++)
                                dataData.addElement(new java.util.Vector());
                                java.util.Vector v2=(java.util.Vector)dataData.lastElement();
                                v2.setSize(v1.size());
                    java.util.Vector v=(java.util.Vector)dataData.elementAt(0);
                    if(column>=v.size())
                        for(int i=0;i<dataData.size();i++)
                            v=(java.util.Vector)dataData.elementAt(i);
                            v.setSize(column+1);
                    if(row<dataData.size())
                        v=(java.util.Vector)dataData.elementAt(row);
                        v.setElementAt(aValue,column);
            };

  • How to create new rows in a JTable dynamically?

    I want to add new rows to a JTable dynamically based on my resultset from the database .
    How to do ?
    Please help me
    Thanks in advance

    Thank u for ur reply .But still i need to clarify something.
    I've used the below code to create a basic table within my frame.
    Object[][] data = {      {"dilipp", "r",      "early", "10","20"}};
    String[] columnNames = {"First Name", "Last Name", "payment", "from", "to"};
    table = new JTable(data, columnNames);
    after this i connect to database and query .The values returned are to be populated in the table created above through say a button "Next" month.
    now my button event goes like this :
    public void actionPerformed(ActionEvent e)
         if (e.getActionCommand().equals("next"))
    here i need to add a new row for the values
    How to add here ?
    please tell me

  • How can I add new row/column into existing jTable?

    Hi add!
    Can you help me how can I add new row/column into existing jTable?
    Tnx in adv!

    e.g
    Create two buttons inside the Table ( "Add New Row" ) and ("Add new Column")
    their handlers are:
    add new row:
    //i supose u already have
    DefaultTabelModel tablemodel = new DefaultTableModel(rowdata, columnNames);
    //and   
       JTabel jtable = new JTable(tablemodel);
    // Handler (row)
    jbtAddRow.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e) {
          if(jtable.getSelectedRow() >= 0 )
              tablemodel.insertRow(jtable.getSelectedRow(), new java.util.Vector());  
           else  
                tablemodel.addRow(new java.util.Vector());
        });to add new columns its the same but inside actionPerformed method:
    ask for e.g "Whats the name for the new column"
    then,
       tablemodel.addColumn(nameOfColumn, new java.util.Vector());   Joao
    Message was edited by:
    Java__Estudante

  • JTable - adding new row

    Hi
    Can someone help me. I have a JTable with a ADD button. When I select the ADD button, I want to be able to bring up a dialog to enter the data for the new row and then click OK on this dialog.
    Does anyone have simple code that does this?
    Regards

    Sorry. Don't know anything about databases.
    But if you know how to do it normally (in the Frame's code) then you just do the same thing in the dialog. You just need to pass the appropriate objects to the dialog so that it can manipulate them.
    Optionally, you could get an Object[ ] from the dialog and have the Frame's code add the row (probably better design).

  • Add new row JTable

    Hi:
    How add a new Row in a JTable

    One way: )]addRow
    Bah! Stupid URL formatter...
    Message was edited by:
    Hippolyte

Maybe you are looking for

  • Reqmt qty of variable size item in purchase requisition

    Hello All I am having a FG "A" & components "B" & "C" out of these two components "B" is variable size item with Base UOM as M, I have given two sizes of "B" as 3M & 2M in the BOM., i.e. material "B" is added two times as a component with variable si

  • Revenue and receivables to profit centers

    hi , can i transfer receivables and revenues both to same profit center. can can one explein me with example how to transfer both ? thanks

  • WSUS - Clients stopped reporting on downstream replicas

    Just looking for some advice on what could be wrong here. Some of our downstream WSUS replicas have stopped 'receiving' updates from machines on the network.  Below is an example of one group affected.  In this case WSUS is on a 2003 server but there

  • R12.1.1 upgrade driver failed due to OKC user connectivity (RHEL 5.9)

    Hi Team, I was in the middle of the R12.1.1 upgrade and the driver failed due to OKC user connectivity . I have checked all the possibilities. Please let me know how to proceed from here. Though I restarted the patch it is failing due to OKC user log

  • Formula node uotput variable

    If i use two different formula nodes with the same output and input variable names will the variables (scope) be the same? In the first formula node i define a variabe "int32 first ==0" then in a seperate node embedded in a for loop structure I write