Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java: Adding Row in JTable
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gumuruh
Java: Adding Row in JTable
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


how about if we already have the JTAble created earlier.

And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method.

Is there any work around for this?

I found that we need to re-create the table as a whole using AbstractModel, (what??)

(--__--)" uh oh....


Advertisement
View Answers

February 9, 2011 at 4:37 PM


Java add row in JTable

import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;

public class InsertRows{
  public static void main(String[] args) {
    new InsertRows();
  }

  public InsertRows(){
    JFrame frame = new JFrame("Inserting rows in the table!");
    JPanel panel = new JPanel();
    panel.setLayout(null);
    String data[][] = {{"Name","Address"}};
    String col[] = {"",""};
    final DefaultTableModel model = new DefaultTableModel(data,col);
    JTable table = new JTable(model);
    JButton b=new JButton("Add Row");
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        model.insertRow(1,new Object[]{"Roseindia","Delhi"});
        }
    });
    table.setBounds(10,10,300,100);
    b.setBounds(10,120,100,20);
    panel.add(table);
    panel.add(b);
    frame.add(panel);
    frame.setSize(500,200);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

You can also visit the following link:

Inserting rows in JTable



Related Tutorials/Questions & Answers:
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
Advertisements
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project for pharmacy .. *pblm:* when i want to enter the details in jtable while running... to add one more row dynamically as a new row 4th if the details are large.but every
Java: Adding Row in JTable
Java: Adding Row in JTable   how about if we already have the JTAble created earlier. And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method. Is there any work around for this? I found
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want
Removing a Row from a JTable
Removing a Row from a JTable       After inserting the data in a JTable, if you wish... the JTable. For removing the data of row from JTable, you will remove it from
Remove JTable row that read txt file records
Remove JTable row that read txt file records  Hi every one. i have a jtable that correctly read data frome file and show them in own. I want to add a "Delete" button that when select a row and clicked button, row must deleted
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djile pak.java
Enabling Row, Column and Cell Selections in a JTable
Enabling Row, Column and Cell Selections in a JTable... to describe how to enable the row, column and cell selections in a JTable... will see the enabling row, column and cell selections in a JTable. When you
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
jtable
jtable  i have build an application and i retrieve data from the database and store it in jtable.now i have to make a checkbox column in each row and also a select all option in header but i am not able to do so.i am getting
JTable - Swing AWT
JTable row selection event   Hi, it will be great if someone can share an example of row selection event in JTable
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container below that row itself and show the required details of the row
java jtable
in which i have to display database records in jtable .now I want to read only the values of particular row at which the jtextfield has been set. and display that in jtable. plz help me with the code
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends AbstractTableModel { public boolean isCellEditable(int row, int column
REPORT WITH JTABLE
(rs.next()) { Vector row = new Vector(columns); for (int i = 1; i <= columns; i++) { row.addElement( rs.getObject(i) ); } data.addElement( row ); } } catch(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane
jtable problem
jtable problem  how to make a cell text hypertext
Jbutton in JTable cells
Jbutton in JTable cells  I am a Java Beginner... I want a code in which I display data in Jtable from database and correspondingly a JButton... with that respective row's data details.. Please help me
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's... { JFrame f; JPanel p; JLabel l; JTextField tf; JButton btn; JTable tb
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button. The values will be entered in this empty row. I have searched on this but could
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
 

 

 

DMCA.com