AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some Strange things in JTable

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
RC
Guest





PostPosted: Fri Dec 08, 2006 3:49 am    Post subject: Some Strange things in JTable Reply with quote



I am try to create a dynamic table.

String[] dataColumns = {"Observation Time", "Value", "Mode"};

DefaultTableModel dataTableModel =
new DefaultTableModel(dataColumns, 100);

// read data into dataTableModel here
// each row is a vector,
// read in another vector for Timestamp, Double and String

JTable dataTable = new JTable(dataTableModel);
dataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
dataTable.setRowSelectionAllowed(true);
dataTable.setCellSelectionEnabled(true);
dataTable.setDragEnabled(true);

JScrollPane scroll = new JScrollPane(dataTable);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setWheelScrollingEnabled(true);

So far so good, everything is working fine.
I can select a row by single click,
select a cell by double clicks,
edit a cell, scroll up and down.

Later I have new data coming, I remove all rows from that
dataTableModel, and read the new data and added to new row to
that dataTableModel. Then I got new data display on the JTable.

So far still in good shape. However, here are the problems I found:

1. I can't select a row any more.
2. I can't edit the a table cell any more.
3. the scroll bar is goen, I can only see a portion of table. I can't
scroll up and down, left and right.

I can still do drag and select table cell by double clicks.
So I can only do select a row by dragging.

Can anyone out there explain or tell me why?

Each time I added a new row, I do

dataTableModel.addRow(vectorRow);
dataTableModel.fireTableDataChanged();

and after I finished added all rows, I do

dataTableModel.fireTableChanged(new TableModelEvent(dataTableModel));

But still no luck at all!
Any idea? Please tell me how to fixed above three problems?

Thank Q very much in advance!
Back to top
Andrew Thompson
Guest





PostPosted: Fri Dec 08, 2006 6:46 am    Post subject: Re: Some Strange things in JTable Reply with quote



RC wrote:
Quote:
I am try ..

Please try to refrain from multi-posting in future, as well.

(X-post to c.l.h.h./g., w/ f-u to c.l.j.h. only)

Andrew T.
Back to top
Douwe
Guest





PostPosted: Sat Dec 09, 2006 11:35 pm    Post subject: Re: Some Strange things in JTable Reply with quote



Quote:
dataTable.setCellSelectionEnabled(true);
dataTable.setDragEnabled(true);

Why turn on dragging ?? Which version of Java are you using ?

Quote:
JScrollPane scroll = new JScrollPane(dataTable);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

Are these not the defaults for a JScrollPane ??

Quote:
Later I have new data coming, I remove all rows from that
dataTableModel, and read the new data and added to new row to
that dataTableModel. Then I got new data display on the JTable.

Where is the data coming from? Is it maybe coming from another thread?

Quote:
Each time I added a new row, I do

dataTableModel.addRow(vectorRow);
dataTableModel.fireTableDataChanged();

That's probable causing a hurricane of events Smile Looking at the method
DefaultTableModel.addRow() it appears to end in the method
insertRow()..

public void insertRow(int row, Vector rowData) {
dataVector.insertElementAt(rowData, row);
justifyRows(row, row+1);
fireTableRowsInserted(row, row);
}


As you can see the method itself is firing a 'TableRowsInserted' event.
I think that will suffice.

Quote:
and after I finished added all rows, I do

dataTableModel.fireTableChanged(new TableModelEvent(dataTableModel));

Don't think this will help much either.

Why don't you refill the model by calling the method
DefaultTableModel.setDataVector() ?

Douwe Vos
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.