How can i add rows to a JTable at run time ??????

hi there
how can i add a row to a JTable at run time? and display the table after the change? thank you.

For adding or removing the rows from the JTable, you have to use the methods on the table model. I would show you a simple implementation of table model.
public class MyTableModel extends AbstractTableModel {
private ArrayList rowsList = null;
private String [] columns = { "Column 1" , "Column 2", "Column 3"};
public MyTableModel() {
rowsList = new ArrayList();
public int getRowCount() {
return rowsList.size();
public int getColumnCount() {
return columns.length;
public void addRow(MyRow myRow) {
//MyRow is any of your object.
rowsList.add(myRow);
fireTableDataChanged();
public void removeRow(int rowIndex) {
rowsList.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
public Object getValueAt(int row, in col) {
MyRow currentRow = (MyRow)rowsList.get(row);
switch (col) {
case 0:
//return the value of first cell
break;
case 1 :
//return the value of second cell
break;
case 2 :
//return the value of third cell
break;
}Then create the table using the TableModel using the constructor new JTable(TableModel) and then when you want to add/remove a row from the table, call myTableModel.addRow(MyRow) or myTableModel.removeRow(rowIndex)....I hope that this solves your problem.

Similar Messages

  • How can I add rows to a JTable based on an Abstract Table Model?

    I have done this ...
    public class myui extends JPanel {
    private AbstractTableModel jTable1Model;
    blah blah
            jTable1Model = new AbstractTableModel() {
                 String[] column = new String[]{"TID", "Name", "Address"};
                 Vector<Vector<Object>> table = new Vector<Vector<Object>>();
                 @Override
                 public int getRowCount() {
                      return table.size();
                 @Override
                 public int getColumnCount() {
                      return column.length;
                 @Override
                 public String getColumnName(int col) {
                      return column[col];
                 @Override
                 public Object getValueAt(int row, int column) {
                      return table.get(row).get(column);
                 @Override
                 public void setValueAt(Object value, int row, int column) {
                      table.get(row).set(column, value);
                      fireTableCellUpdated(row, column);
                 public void insertRow() {
                      Vector<Object> columns = new Vector<Object>();
                      columns.add(null);columns.add(null);columns.add(null);
                      table.add(columns);
                      fireTableRowsInserted(0, table.size());
    blah blah
        public synchronized void ImportVisitorDataToJTable1(Object value, int row, int col) {
            jTable1Model.InsertRow();  <-----///// This line not being recognised as a valid member function call
           jTable1.setValueAt(value, row, col);
    }I thought to insert a row I can define a function in the abstracttablemodel class and then instantiate the class and override or create new methods that I can use.
    But after instantiating the class and overriding appropriately and adding the insertRow function, when I try to use it in ImportVisitorDataToJTable1 as seen above its not being recognized as a funtion of jTable1Model

    1. respect naming conventions. Example: myui --> MyUI, ImportVisitorDataToJTable1 -->importVisitorDataToJTable1
    2. convert Anonymous to Member: AbstractTableModel --> MyTableModel
    3. row parameter makes no sense here as it depends on current row count:
        public synchronized void importVisitorDataToJTable1(Object value, int col) {
            int row = jTable1Model.getRowCount();4. here is a more adequate "fireTable.."-call for insertRow:
    fireTableRowsInserted(table.size() - 1, table.size() - 1);
    5. check if you can take advantage using DefaultTableModel as suggested by Maxideon.

  • How can i add rows in a tabular form

    Hi,
    How can i add rows in a tabular form with out updating in database and after adding the rows one by one and after filling the data then iwant to submit them all at once.Please help me on this.
    Thanks

    Hello Leandro,
    In the Add_Rows page process, there is a box for "Number Of Rows". Change that value and you change the number of rows that get added. The default is 1.
    Don.
    You can reward this reply by marking it as either Helpful or Correct :)

  • How can i add an external hard drive to my time capsule

    How can i add an exteranl hard drive to my time capsule

    yes, plug a USB drive .. correctly formatted.. in.

  • How can i add row selector

    Hi,
    i want to add row selector in my reports. as we do in sql command promt.
    i want to create select list with values like 500,1000,2000,6000 and so on. if i choose 500 in select list it show 500 records in report,if i choose 1000 then show 1000 rows in report.how can i do this.
    is it possible? if it is then how can i do this.
    Thanks & Regards
    nisha

    In the Report pagination Settings( report Attributes ->pagination" ) , there is a field by the name "*Number of Rows (Item)*" , Choose your item there.

  • HT1175 How can i add a 1TB hard disc to my time capsule with usb?

    I  bought a 2TB time capsule and now I have two questons actialy. First I want to add a 1TB external HD to my TC, second I want to access my data's from another places with any network. These are possible and how can I do these things please help me?

    gencali wrote:
    When I tried to do remote access settingd, this problem get; The DHCP range you have entered conflicts with the WAN IP adress of your Apple Wi-Fi base station. I tried diffents things which are on google but it is not work.
    What wan ip address do you have.. if the TC is behind an existing router then it will not work directly. The TC has to be bridged.. and you will need to forward port 548 TCP to the IP address of the TC.
    And my HD's format type is exFat and I can use it on my mac, why is not work on TC, do you know? Finally I have one more question how can I see my files on ipad or iphone? By the way thanks a lot.
    ExFat will not work on a TC.. Fat16 or Fat32 (both not recommended btw) or HFS+.. note if you use fat you cannot use AFP.
    Google is your friend.. this took 10sec or less to find.
    http://support.apple.com/kb/HT2426?viewlocale=en_US
    Finally I have one more question how can I see my files on ipad or iphone? By the way thanks a lot.
    ipad or iphone, ie iOS devices do not use AFP, so the access is only via SMB.. and you need to purchase an App to get that ability.
    Again, 10sec on google.. http://itunes.apple.com/us/app/filebrowser-access-files-on/id364738545?mt=8
    Lots of examples though. I have no idea of good and bad ones.. use google.

  • Please!!!!!!   How can i add rows in html table dynamically [use jsp,bean]

    hello, i am a fresher in jsp. i want to add new rows in html table dynamically.In my coding, just only shows in one row . please help my problem with correct coding and i don't want to use database. Thanks ...............!
    Here is my coding-------------------
    ---------------- form.jsp --------------------->
    <%@ page import="java.util.*,newtest1.Validation" %>
    <jsp:useBean id="mybean" scope="page" class="newtest1.Validation" />
    <jsp:setProperty name="mybean" property="name" param="name" />
    <jsp:setProperty name="mybean" property="age" param="age" />
    <% s[i][j] %>
    <html>
    <head><title>Form</title></head>
    <body>
    <form method="get">
    <table border="0" width="700">
    <tr>
    <td width="150" align="right">Name</td>
    <td width="550" align="left"><input type="text" name="name" size="35"></td>
    </tr>
    <tr>
    <td width="150" align="right">Age</td>
    <td width="550" align="left"><input type="text" name="age" size="35"></td>
    </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr><td> </td></tr>
    <tr><td><input type="submit" name="submit" value="ADD"></td></tr>
    <tr><td> </td></tr>
    <tr><td width="100%" align="center" border=1>
    <% int count=mybean.getStart();
    for(int i=count; i<count+1; i++) { %>
    <tr>
    <td><jsp:getProperty name="mybean" property="name" /></td>
    <td><jsp:getProperty name="mybean" property="age" /></td>
    <td><%= count %></td>
    <% count+=1; %>
    </tr>
    <% } %></td></tr>
    </table>
    </form>
    </body>
    </html>
    ----------------- Validation.java ----------------->
    package newtest1;
    import java.util.*;
    public class Validation {
    private String name;
    private String age;
    static int start=0;
    public Validation() {    name=null;
    age=null;
    ++start;}
    public void setName(String username) { if(username!="")
    name=username;
    public String getName() { return name;  }
    public void setAge(String userage) {  if (age!="")
    {age=userage;}
    public String getAge() {  return age;   }
    public int getStart() {
    return start; }

    Hi, Do you mean to say,
    You have an HTML page in which you have a text field and an add button. If you enter anything in that text field and click on Add button the text field contents should be displayed in the same HTML page and you should be able to go on entering new values into the text field and you should be able to retain and display all the previously entered values..
    and finally the list of added items are not stored in the database..
    If this is the case
    i. Your html form should be submitted to the same page.
    ii. You need to have a Vector which holds the entered values.
    iii. Bind the vector object to the request object and collect the same vector object from the request and display its contents...
    I think this would help...

  • How can select Multiple Rows in a Jtable

    Dear Forum
    i am working on jclient\swing.
    I want to select More than one row at a time from a table
    I am trying the following code at INIT but it is not working.
    jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    Please suggest me for the same.
    Thankx

    Girdhar,
    I tried with JDeveloper 9.0.3 and it worked.
    Either you are using another JDeveloper version, or you need to specify what you mean with "is not working".
    Frank

  • How to initilize the size of rows in an jtable in run time

    i am trying to retrieve data from a oracle database and display them in an jtable ,but i could not figure out how to increase the size of the table based on the number of records fetched in runtime. i also want to add checkbox for each enrty made in the jtable such that by cheching the box ,i could select the data and process it in futher frames. i use an netbean5 version for design.kindly give me giudence.

    Best thing to do is write your own table model and a Cell Renderer for the check box.
    Please follow the "How to use tables" tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • How can I debug the Call Library Function at run-time

    I've written a VI using the CLF to call a DLL which was compiled off-site by another engineer using MSVC. Even though the VI runs without flagging any errors, the VI is not doing what I expect. Is there any way of finding out if the DLL is been called correctly? The first function that is called doesn't return any value, but I think that it should. Does this mean that the DLL is not being called correctly? Note also that the DLL works fine with a JAVA GUI.

    Make sure that you are specifying the proper function prototype in the call library function. If you are slightly off the call will not work properly. Ask the offsite engineer to provide you with this data. Another tip is to build the dll with the option to show front panel when called. You can actually popup the dll like you would a subvi. If you design it with test indicators showing on the front panel that is a great way to determine if it is working. Hope this helps.
    BJD1613
    Lead Test Tools Development Engineer
    Philips Respironics
    Certified LV Architect / Instructor

  • 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

  • How can I add a row into a JTable with JButton

    Hi all. I have the following code:
    package gui;
    import db.*;
    import javax.swing.table.AbstractTableModel;
    import java.util.ArrayList;
    public class FoundersTable extends AbstractTableModel{
        private static final int COLUMNS = 8;
        private String columnNames[] = {"��� ����", "���", "�������", "�������", "���������", "��������",
                "����� �� ����������", "������ �� ����, �����"};
        private ArrayList data;
        public FoundersTable(){
            data = new ArrayList();
        public int getRowCount() {
            return data.size();
        public int getColumnCount() {
            return columnNames.length;
        public String getColumnName(int colIndex) {
            return columnNames[colIndex];
        public Object getValueAt(int rowIndex, int columnIndex) {
            return ((ArrayList)data.get(rowIndex)).get(columnIndex);
        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            ((ArrayList)data.get(rowIndex)).set(columnIndex, value);
            fireTableCellUpdated(rowIndex, columnIndex);
        public void addRow(ArrayList neueZeile) {
            data.add(neueZeile);
            int index = data.size() - 1;
            fireTableRowsInserted(index, index);
        public void removeRow(int index) {
            data.remove(index);
            fireTableRowsDeleted(index, index);
        public void removeAllRows() {
            data.clear();
            fireTableRowsDeleted(0, 0);
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
    }Now in my MainJFrame class I have one button for additing and one button for removing a selected row. How can I add/remove rows with this two buttons.
    Thanks

    No my question is how can I add and remove rows WITH buttons My point was the code is the same. You use the addRow(...) method. Why did you write an addRow(...) method if you aren't going to use it?
    I don't understand your problem. Do you not know how to write an ActionListener?

  • How can I add action listener to a cell or row in a table?

    hi there
    I need to be able to click on one cell or one row in a table, and perform some action, like openning a dialog or something. how can i add listener?

    // See How to Use Tables in tutorial. You will get one idea about Table Renderer and Editors.
    // If u understand the concept, ur problem is very easy to solve by adding Editor to your column.
    "You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell. When the user starts to edit a cell's data, a cell editor takes over the cell, controlling the cell's editing behavior.
    Here, While tabing thru the table row, default all cell editors are JLabels. (Not editables)
    So u can make it those cells are editable JTextFields or JComboBoxes based on the column while tabbing. And you can add Listeners to that fields too. So those editable fields are called Editor Components.
    // see javax.swing.DefaultCellEditor class for more description
    Here i am adding my own JTextField editor to 3rd column of a table by using
    mytable.getColumnModel().getColumn(2).setCellEditor(editor );
    Here editor is a obj of below class. (Not complete..class)
    public class JbuiEditor extends DefaultCellEditor implements // any listener {
    public JbuiEditor(JTextField tField) {
    super(tField);
    setClickCountToStart(1);
    tField.addFocusListener(this);
    this.editorComponent = tField;
    public Component getComponent(){
         return editorComponent;
    public Component getTreeCellEditorComponent(JTree tree, Object value,
                                  boolean isSelected,
                                  boolean expanded,
                                  boolean leaf, int row) {
         String StringValue = tree.convertValueToText(value, isSelected,
                             expanded, leaf, row, false);
         delegate.setValue(stringValue);
         return editorComponent;
    public Object getCellEditorValue() {
    return super.getCellEditorValue();
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int row, int column) {
    super.getTableCellEditorComponent(table,value,isSelected,row,column);
    ((JTextField)editorComponent).setText(value.toString());
    //Here u can add any type of listener to this Editor component.like..
    ((JTextField)editorComponent).addActionListener(..);
    ((JTextField)editorComponent).addFocusListener(..);
    return editorComponent;
    Hope gives some idea.

  • How can I add the number of columns/row starting with the build in "Text Report" example in the LabVIEW

    Hi All,
    I am wondering how can I add the numbers of row and column from the existing build-in "text report"
    VI ? If possible, would you mind showing me step-by-step because I am a new user and I am not familiar with the labview software.
    Thanks

    Hi,
    Easy text Report is for saving to a file. Do you mean you just want to add the totals of two arrays and write that? In that case I would just append the totals before writing to file.
    Jeff | LabVIEW Software Engineer

  • How can i add a MouseMotionlistener  to the cells in the JTable?

    hi !
    how can i add a MouseMotionlistener to the cells in the JTable?

    yes i have.but that is different from adding MouseMotionlistener to the cells for me .
    i just want get the values where the mouse moves to .

Maybe you are looking for

  • Accessing mysql database from oracle using dg4odbc

    I've been trying to create a database link from a MySQL database to Oracle using the Oracle dg4odbc gateway. I downloaded and installed DataDirect's ODBC package which includes mysql ODBC library (ddmysql24.so) and a generic ODBC libary (libodbc.so).

  • Archiving pdf-document in external store ?

    hi there, i have a projekt, where i have to archive pdf-files on a external archive (ixos). i use the FM 'ARCHIV_CREATE_SYNCHRON_META' to archive the pdf-files. the big problem is the following: the name of the original pdf-file is not saved. there i

  • Issues with Receive Adapter receiving a file that has not completed uploading while send multiple files on the Send Adapter

    Hello, I am only a few weeks old into BizTalk so I am new to this application.  The pieces I have for my development environment consists of the following: FTP Server ---[SFTP Adapter]---> BizTalk 2013 ---[FILE Adapter]---> Internal Network Share Dri

  • Shrinking Vertical Group Lines

    When sorting activities by WBS in Contractor is there a way to shrink the vertical group lines. Default colours are yellow and green. They are massive after a few nested groups. Any suggestions? Thanks, Justin

  • Funktion Call in the C-kernel

    Hello all in the file sapactab.h (Based in Kernel) is the coding for the ABAP Statement Call. Does anybody know with C-Statement (in c) is it. Thanks for your help Chris