update JTable

Discussion in 'Java' started by pat270881, Apr 5, 2005.

  1. pat270881

    pat270881 Guest

    Hello,

    I have a JTable with some lines and I implement the function with which
    the user can select one line and delete it. The problem is that the
    JTalbe is not automatically updated and the deleted line is still
    displayed. How can I update my JTable automatically?

    thx
     
    pat270881, Apr 5, 2005
    #1
    1. Advertising

  2. "pat270881" <> writes:

    > How can I update my JTable automatically?


    Your model needs to call fireTableRowsDeleted(row, row) if you extend
    AbstractTableModel, otherwise you need to create and deliver that
    event yourself to the listeners.
     
    Tor Iver Wilhelmsen, Apr 5, 2005
    #2
    1. Advertising

  3. pat270881

    pat270881 Guest

    Hallo,

    But I don't use a AbstractTableModel. I use the following code for
    creating the JTable and the DefaultTableModel:

    static JTable tblSearchResults;
    private DefaultTableModel model;

    model = new DefaultTableModel(new Object[]{"TextName", "Thesaurus"},0);
    tblSearchResults = new JTable(model);
    tblSearchResults.setAutoscrolls(true);
    tblSearchResults.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //tblSearchResults.setColumnSelectionAllowed(true);
    tblSearchResults.setRowSelectionAllowed(true);
    TableColumn col = tblSearchResults.getColumnModel().getColumn(0);
    int width = 100;
    col.setPreferredWidth(width);

    TableColumn col1 = tblSearchResults.getColumnModel().getColumn(1);
    int width1 = 607;
    col1.setPreferredWidth(width1);

    JScrollPane scrollPane = new JScrollPane(tblSearchResults);

    scrollPane = tblSearchResults.createScrollPaneForTable(
    tblSearchResults );
    tblSearchResults.setBounds(13,48,707,264);
    tblSearchResults.setVisible(true);
    scrollPane.setBounds(13,48,707,264);
    scrollPane.setVisible(true);
    this.getContentPane().add(scrollPane);

    The data with which the JTable is filled comes from a Database.

    Can anybody help me how I can realize the update in that case?

    thx
     
    pat270881, Apr 6, 2005
    #3
  4. pat270881

    John McGrath Guest

    > On 4/5/2005 at 5:57:20 PM, Tor Iver Wilhelmsen wrote:

    > > Your model needs to call fireTableRowsDeleted(row, row) if you extend
    > > AbstractTableModel, otherwise you need to create and deliver that
    > > event yourself to the listeners.


    On 4/6/2005 at 5:01:22 AM, pat270881 wrote:

    > But I don't use a AbstractTableModel. I use the following code for
    > creating the JTable and the DefaultTableModel:


    Then you *do* use AbstractTableModel:

    public class DefaultTableModel extends AbstractTableModel

    However, DefaultTableModel should already be calling
    fireTableRowsDeleted() for you, assuming you are using the
    DefaultTableModel methods to delete the row. Since you did not post that
    code, it is impossible to tell.

    --
    Regards,

    John McGrath
     
    John McGrath, Apr 6, 2005
    #4
    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. Tivo Escobar
    Replies:
    1
    Views:
    7,551
    manusa
    Apr 12, 2007
  2. Seref Arikan

    Custom JTable update problem

    Seref Arikan, Jan 26, 2004, in forum: Java
    Replies:
    1
    Views:
    3,014
    Christian Kaufhold
    Jan 26, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,813
    Andrew Thompson
    Feb 14, 2007
  4. Daniele Futtorovic

    Re: update JTable

    Daniele Futtorovic, Jul 17, 2008, in forum: Java
    Replies:
    0
    Views:
    502
    Daniele Futtorovic
    Jul 17, 2008
  5. Haircuts Are Important
    Replies:
    3
    Views:
    414
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page