aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dyanmically adding a Row to JTable" Watch "Dyanmically adding a Row to JTable" New topic
Author

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[]=
{
"1",
"2"

};

JFrame parentFrame;
String columnNames[]=
{
"Name",
"Type",
"Value"
};

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

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

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

initColumnWidth(columnsize);
setCellEditor(1,jCType);
}

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


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

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

tableModel.addRow(nulldata);
}

public void deletefunc()
{

tableModel.removeRow(selectedRow);
}

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
Regards
vinaya

when i press enter i should getj
[ February 09, 2002: Message edited by: vinaya kumar ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dyanmically adding a Row to JTable