Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > update JTable

Reply
Thread Tools

update JTable

 
 
pat270881
Guest
Posts: n/a
 
      04-05-2005
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

 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      04-05-2005
"pat270881" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
pat270881
Guest
Posts: n/a
 
      04-06-2005
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(ListSelectionMod el.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

 
Reply With Quote
 
John McGrath
Guest
Posts: n/a
 
      04-06-2005
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update On The Windows Phone 7 Update Update Lawrence D'Oliveiro NZ Computing 2 02-25-2011 08:03 AM
Re: update JTable Daniele Futtorovic Java 0 07-17-2008 02:13 PM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Custom JTable update problem Seref Arikan Java 1 01-26-2004 05:31 PM



Advertisments