Some Strange things in JTable

Discussion in 'Java' started by RC, Dec 7, 2006.

  1. RC

    RC Guest

    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!
    RC, Dec 7, 2006
    #1
    1. Advertising

  2. RC wrote:
    > I am try ..


    ...to make enemies through your consistent use of multi-posting?

    Please refrain from multi-posting.

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

    Andrew T.
    Andrew Thompson, Dec 8, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexey Smirnov

    IIS Security strange things

    Alexey Smirnov, Mar 1, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,825
    Alexey Smirnov
    Mar 3, 2004
  2. Tivo Escobar
    Replies:
    1
    Views:
    7,276
    manusa
    Apr 12, 2007
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    vs2005 publish website doing bad things, bad things

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    589
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 25, 2006
  4. Tintin92
    Replies:
    1
    Views:
    1,676
    Andrew Thompson
    Feb 14, 2007
  5. Haircuts Are Important
    Replies:
    3
    Views:
    302
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page