update JTable

P

pat270881

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
 
T

Tor Iver Wilhelmsen

pat270881 said:
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.
 
P

pat270881

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
 
J

John McGrath

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top