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

[349 byte] By [dayanandabva] at [2007-11-27 8:53:54]
# 1
> could you suggest what could be the problem?I suggest posting some code that displays the undesirable behavior.
mbmerrilla at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 2

> could you suggest what could be the problem?

Your code.

You've asked enough questions in the past to know that we are wasting time reading a question with such limited information. We have no idea how you craate the table or add it to the GUI. The problem could be anything.

If you really want help, then post your SSCCE. I'm sure you've been given the link explaining what a SSCCE is in your other postings.

camickra at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 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

dayanandabva at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 4

You've stated that it's a problem with the display of data in a table; you've also stated that you can't get a small sample to exhibit the same behavior. Clearly, you're doing something different in your real work that isn't being replicated in your incomplete example.

I'd guess it has something to do with the getValueAt() method, which you didn't (or can't) include the meat of.

It looks like you're including sorting capability in your table; the source code I use when I need this functionality is at:

http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TableSorterDemoProject/src/components/TableSorter.java

That probably won't make any difference in your actual problem, but may simplify your life somewhat.

Message was edited by:

mbmerrill

mbmerrilla at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 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.

camickra at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 6

thanks for suggestions,

i am doing some calucation for each column on getValueat() method, is this causing the problme?, because i commented the calucation code and hard code some value to each column than it is displaying properly,

and one more thing i am getting refresh data to the data model. that time also corresponding calucation should be done for that column.

i tried to put EDT thread to gui still not working.

I need suggestion.

camickr has you suggested i removed one of the model, itself it is not all required, and i check all overied method also. thanks for valuable suggestion.

thanks

daya

dayanandabva at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 7

> i am doing some calucation for each column on

> getValueat() method, is this causing the problme?,

> because i commented the calucation code and hard code

> some value to each column than it is displaying

> properly,

Hardcoded values work, and calculated values don't?

Yep, I'm gonna go ahead and guess your problem is in the calculations.

mbmerrilla at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 8

The getValueAt(...) method should not be doing calculations. Its not efficient as this method is used every time the table need to be rendered.

If you are doing a calculation because the value of a cell has been updated and another cell is dependent on this value then you should be using a TableModelListener to do this calculation once. This posting shows a simple example of this approach:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133

camickra at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 9
i will go through the link.thanks
dayanandabva at 2007-7-12 21:12:10 > top of Java-index,Desktop,Core GUI APIs...