Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2006

Tip: Looking for answers? Try searching our database.

Some Strange things in JTable

Thread view: 
RC - 07 Dec 2006 21:47 GMT
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!
hiwa - 08 Dec 2006 00:06 GMT
> I am try to create a dynamic table.
>
[quoted text clipped - 52 lines]
>
> Thank Q very much in advance!
Use setDataVector() method.
And, in general, you don't need to call any fireXxxx() method after you
call table data change methods on a DefaultTableModel.
Andrew Thompson - 08 Dec 2006 00:46 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.