data in jtable not showing properly when i open a window
hi all,
Data is not showing properly when i open a window itself,
some of the rows shows data and some of the rows not showing data,
and in some rows data is breaking.
when i click inside the table than data will be display in row.
could you suggest what could be the problem?
thanks in advance.
Daya
# 3
thanks for your replay,
i know that i have to create sscce and i have to post here.
i tried to create demo but demo what i created is working fine.
and i am not able to generate the same, thats why asked for suggestion.
i am using AbstractTableModel and DefaultTableModel models
can you people tell me the way i coded in default and abstract model
is causing that problem.
private class ATSRolloverTableModel extends DefaultTableModel
{
public boolean isCellEditable(int r, int c)
{
return true;
}
public void setValueAt(Object aValue, int r, int c)
{
super.setValueAt(aValue, r, c);
}
public int getRowCount()
{
return m_conRollover.getDataArray().size();
}
public int getColumnCount()
{
return m_conRollover.getColumnNames().size();
}
public String getColumnName(int c)
{
return m_conRollover.getColumnNames().get(c);
}
public Class getColumnClass(int c)
{
switch (c)
{
case 0:
return Integer.class;
case 1:
return String.class;
case 2:
return Double.class;
case 3:
return Double.class;
case 4:
return Double.class;
case 5:
return Double.class;
case 6:
return Double.class;
case 7:
return Double.class;
case 8:
return Double.class;
default:
return Double.class;
}
}
public Object getValueAt(int row, int column)
{
//i am doing some Calculation doing some caluclation for that row and that colum and returning the value
return value;
}
}
private class ATSSortFilterModel extends AbstractTableModel
{
private ATSRolloverTableModel model;
int[] indexes;
public String[]tableHeadersArray;
booleanisAscent = true;
public ATSSortFilterModel(ATSRolloverTableModel model)
{
this.model = model;
}
public void addMouseListener(final JTable table)
{
table.getTableHeader().addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent event)
{
// check for double click
// if (event.getClickCount() < 2)
// return;
int tableColumn = table.columnAtPoint(event.getPoint());
m_btnSorterRenderer.setPressedColumn(tableColumn);
m_btnSorterRenderer.setSelectedColumn(tableColumn);
if (tableColumn == 0) // For Serial column no need of sorting
{
return;
}
if (ATSSorterButtonRenderer.DOWN == m_btnSorterRenderer.getState(tableColumn))
{
isAscent = true;
}
else
{
isAscent = false;
}
// translate to table model index and sort
int modelColumn = table.convertColumnIndexToModel(tableColumn);
sortByColumn(modelColumn, isAscent);
}
});
}
public Object getValueAt(int row, int col)
{
int rowIndex = row;
if (indexes != null)
{
rowIndex = indexes[row];
}
return model.getValueAt(rowIndex, col);
}
public void setValueAt(Object value, int row, int col)
{
int rowIndex = row;
if (indexes != null)
{
rowIndex = indexes[row];
}
model.setValueAt(value, rowIndex, col);
}
public int[] getIndexes()
{
int n = getRowCount();
if (indexes != null)
{
if (indexes.length == n)
{
return indexes;
}
}
indexes = new int[n];
for (int i = 0; i < n; i++)
{
indexes[i] = i;
}
return indexes;
}
public int getRowCount()
{
return model.getRowCount();
}
public String getColumnName(int c)
{
return model.getColumnName(c);
}
//
public int getColumnCount()
{
return model.getColumnCount();
}
public Class getColumnClass(int col)
{
// return super.getColumnClass(col);
switch (col)
{
case 0:
return Integer.class;
case 1:
return String.class;
case 2:
return Double.class;
case 3:
return Double.class;
case 4:
return Double.class;
case 5:
return Double.class;
case 6:
return Double.class;
case 7:
return Double.class;
case 8:
return Double.class;
default:
return Object.class;
}
}
}
thanks
daya
# 5
> i tried to create demo but demo what i created is working fine
There you go, you just proved the point that the problem is not with the table, but with your code.
So now you compare the working code with the code that doesn't work to find the difference. We can't do that for you because we don't have the code to work with!!!
I have no idea why you are creating custom TableModels. The Swing tutorial on "How to Use Tables" has a working example or sorting that does not require you to create a custom TableModel. If you want to overrid the getColumnClass() method, thats fine but there is no need to override the other methods.
Like I said above start with the working example. Then create a custom TableModel that overrides one method and see if it still works. If it does then you can try overriding another method and test again. But don't override 20 methods at the same time. If you have a problem you don't know which method is causing the problem.
Learn the basics of problem solving.