kohinoor2007
Programmer
Hi Guys,
In the following piece of code,Iam creating a table ,having 2 rows.The problem for me is that apart from the header row,the other 2 rows are not getting displayed.
When debugged the rowcount vector shows zero.
Also when I tried to add the table to the panel without putting it into a scrollpane,only the header row is getting displayed.
Tried setting "setPrefferedSize" on the table.No use...
What could be the reason?
Thanks in advance..
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class ReprintAssemblyViewPanel extends ContentPanel {
private JTable table;
public ReprintAssemblyViewPanel(){
setLayout(new GridLayout(1,0));
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Reprint assembly View"),
BorderFactory.createEmptyBorder(5, 5, 5,
5)));
initialiseTable();
}
public void initialiseTable(){
Vector rowData = new Vector();
Vector row1 = new Vector();
row1.addElement("MP");
row1.addElement("");
row1.addElement("");
rowData.addElement(row1);
Vector row2 = new Vector();
row2.addElement("MP");
row2.addElement("");
row2.addElement("");
rowData.addElement(row2);
Vector columnNames = new Vector();
columnNames.addElement("MP-Range");
columnNames.addElement("Start");
columnNames.addElement("End");
TableModel model = new
ReprintTableModel(rowData,columnNames);
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
}
class ReprintTableModel extends DefaultTableModel{
private Vector rowData = null;
private Vector columnNames = null;
public ReprintTableModel(Vector rowData1,Vector
columnNames1){
super(rowData1,columnNames1);
this.rowData = rowData1;
this.columnNames = columnNames1;
}
public int getRowCount(){
return rowData.size();
}
public int getColumnCount(){
return columnNames.size();
}
public Class getColumnClass(int columnIndex){
return getValueAt(0,columnIndex).getClass();
}
public boolean isCellEditable(int row,int col){
return false;
}
}
}
In the following piece of code,Iam creating a table ,having 2 rows.The problem for me is that apart from the header row,the other 2 rows are not getting displayed.
When debugged the rowcount vector shows zero.
Also when I tried to add the table to the panel without putting it into a scrollpane,only the header row is getting displayed.
Tried setting "setPrefferedSize" on the table.No use...
What could be the reason?
Thanks in advance..
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class ReprintAssemblyViewPanel extends ContentPanel {
private JTable table;
public ReprintAssemblyViewPanel(){
setLayout(new GridLayout(1,0));
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Reprint assembly View"),
BorderFactory.createEmptyBorder(5, 5, 5,
5)));
initialiseTable();
}
public void initialiseTable(){
Vector rowData = new Vector();
Vector row1 = new Vector();
row1.addElement("MP");
row1.addElement("");
row1.addElement("");
rowData.addElement(row1);
Vector row2 = new Vector();
row2.addElement("MP");
row2.addElement("");
row2.addElement("");
rowData.addElement(row2);
Vector columnNames = new Vector();
columnNames.addElement("MP-Range");
columnNames.addElement("Start");
columnNames.addElement("End");
TableModel model = new
ReprintTableModel(rowData,columnNames);
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
}
class ReprintTableModel extends DefaultTableModel{
private Vector rowData = null;
private Vector columnNames = null;
public ReprintTableModel(Vector rowData1,Vector
columnNames1){
super(rowData1,columnNames1);
this.rowData = rowData1;
this.columnNames = columnNames1;
}
public int getRowCount(){
return rowData.size();
}
public int getColumnCount(){
return columnNames.size();
}
public Class getColumnClass(int columnIndex){
return getValueAt(0,columnIndex).getClass();
}
public boolean isCellEditable(int row,int col){
return false;
}
}
}