i am trying to add different Panels in differnt rows of same column..
But each time i am getting the default panel which is being retuned by the MyTableCellRenderer class which i have implemented from TableCellRenderer .
Would you like reply whats wrong in my approach...Can anyone modify my code???
public class TablePanel extends JPanel
{
JTable alertInsertTable;
JScrollPane alertInsertPane;
String columnnames[]={"Insert Alert"};
Object[][] values={
{
new JPanel()
}
};
DefaultTableModel tableModel= new DefaultTableModel(values,columnnames);
TablePanel()
{
setLayout(new BorderLayout());
alertInsertTable= new JTable(tableModel);
alertInsertPane = new JScrollPane(alertInsertTable);
alertInsertTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
this.add(alertInsertPane,BorderLayout.CENTER);
setDataInTable();
}
public void setDataInTable()
{
int count=0;
alertInsertTable.setRowHeight(80);
MyTableCellRenderer ob=new MyTableCellRenderer();
this.alertInsertTable.getColumn("Insert Alert").setCellRenderer(ob);
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
panel1.add(new JLabel("HIiiiiiiiiiiiiiii"));
panel2.add(new JLabel("Hellooooooooooooo"));
Object[] ob1={panel1};
Object[] ob2={panel2};
model.addRow(ob1);
//its always adding to the Panel with label new JLabel("Oppsssss")
//which is the panel instance returned by MyTableCellRender
model.addRow(ob2);
// this also adding to the Panel with label new JLabel("Oppsssss")
//which is the panel instance returned by MyTableCellRender
// ? What code should i write here so that i can add panel1 and panel2
//which i have created here.
}
}
class MyTableCellRenderer extends JPanel implements TableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex)
{
JPanel panel = new JPanel();
panel.add(new JLabel("Oppsssss"));
return panel;
}
}