Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Swing / AWT / SWT and the fly likes Dyanmically adding a Row to JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dyanmically adding a Row to JTable" Watch "Dyanmically adding a Row to JTable" New topic

Dyanmically adding a Row to JTable

vinaya kumar
Ranch Hand

Joined: Jan 20, 2002
Posts: 70
Class A extends MasterTable
JComboBox jCType;

String type_arr[]=


JFrame parentFrame;
String columnNames[]=

int columnsize[]= {120,80,190};

Object data[][]={
" ","",new Boolean(false)
public InfoDefn(JFrame parent)
String titleString = "Definition";

parentFrame =parent;
jCType=new JComboBox(type_arr);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new RowSelectionListener());


public static void main(String args[])
JFrame test=new JFrame("test");
test.getContentPane().add(new InfoDefn(test),BorderLayout.CENTER);

public void addfunc()
** This Add Null Row
System.out.println("The Value Added is ");

Object nulldata[]=
"","",new Boolean(false)


public void deletefunc()


public void modifyfunc()


public void pastefunc()

public void cutfunc()

public void copyfunc()


Here is the brief descr of the above code
i am displaying a table with first row uneditable
second row is sometimes combobox and third row boolean
I have a master table class which implements the listeners from various
events like popupmenu,enter key.
MasterTable Class has inside it a inner class extending
DefaultTableModel which has the setValueAt function
Mastertable is abstract which will addfunc for adding row
similar call deletefunc for deleting row

Intially my table had no data..
implies it will show one row.
hence we have
Object [][]data = {{"","",new Boolean(false)}};
i add data and then i press enter ...
addfunc is called
my problem starts here
i am using setValueAt in MasterTable ,
where in data[row][col] is used ,
which intially is set to 1 row and 3 column
now i am adding one more row! but data is 2D array
i can't increment size of data array...
so ! i will get Array Index out of BoundExpection
further i want dynamic tooltip...
{tooltip will show complete value in the cell}
so i have added tootip code in setValueAt.
if i comment out the setValueAt code,
i am able to add new row,but
1) boolean column shows false instead of the jcheckbox.
2) How do i add Dynamic Tool Tip...
whatz the work around for this...
Thanks a Lot in Advance

when i press enter i should getj
[ February 09, 2002: Message edited by: vinaya kumar ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Dyanmically adding a Row to JTable