Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTable help

Reply
Thread Tools

JTable help

 
 
barichards21@gmail.com
Guest
Posts: n/a
 
      06-05-2007
I'm pretty new programming with swing and I'm running into a problem
setting up a table. I'm using the DefaultTableModel instead of
setting up my own because I don't need to do anything too complex with
it. I'm having a problem though when I try to remove rows. For
example if I remove the first row, the information shows up correctly
on my table and shifts everything up. But if I then try to reference
the information in the first row it gives me the information of the
row I just deleted. I'm sure it's something stupid but I can't seem
to figure it out. Here's the code I'm using at the moment:

instantiating the table:

tblPhoneNumbers = new JTable(new DefaultTableModel(
new Object[][]{{"",""}},
new Object[]{"Number", "Type"})
);


action to remove the selected row:

protected void btnRemovePhoneActionPerformed(ActionEvent evt) {
DefaultTableModel phoneDm = (DefaultTableModel)
tblPhoneNumbers.getModel();
int selectedRow = tblPhoneNumbers.getSelectedRow();
int numRows = tblPhoneNumbers.getRowCount();
if(selectedRow >= 0 && selectedRow < numRows-1)
{
phoneDm.removeRow(selectedRow);
}
}

 
Reply With Quote
 
 
 
 
SadRed
Guest
Posts: n/a
 
      06-05-2007
On Jun 5, 11:49 pm, (E-Mail Removed) wrote:
> I'm pretty new programming with swing and I'm running into a problem
> setting up a table. I'm using the DefaultTableModel instead of
> setting up my own because I don't need to do anything too complex with
> it. I'm having a problem though when I try to remove rows. For
> example if I remove the first row, the information shows up correctly
> on my table and shifts everything up. But if I then try to reference
> the information in the first row it gives me the information of the
> row I just deleted. I'm sure it's something stupid but I can't seem
> to figure it out. Here's the code I'm using at the moment:
>
> instantiating the table:
>
> tblPhoneNumbers = new JTable(new DefaultTableModel(
> new Object[][]{{"",""}},
> new Object[]{"Number", "Type"})
> );
>
> action to remove the selected row:
>
> protected void btnRemovePhoneActionPerformed(ActionEvent evt) {
> DefaultTableModel phoneDm = (DefaultTableModel)
> tblPhoneNumbers.getModel();
> int selectedRow = tblPhoneNumbers.getSelectedRow();
> int numRows = tblPhoneNumbers.getRowCount();
> if(selectedRow >= 0 && selectedRow < numRows-1)
> {
> phoneDm.removeRow(selectedRow);
> }
> }


> if I then try to reference
> the information in the first row

I suspect the code is wrong.


 
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
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
need JTable help Fred Java 11 05-27-2004 06:33 AM
JAVA HELP: Beans.instantiate, JTable, JBuilder T.R. Diaz Java 0 11-08-2003 11:44 PM
I require a Sortable JTable. Please Help. C-man Java 12 10-14-2003 12:50 AM



Advertisments