Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

JTable help

Thread view: 
barichards21@gmail.com - 05 Jun 2007 15:49 GMT
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);
        }
    }
SadRed - 05 Jun 2007 23:49 GMT
On Jun 5, 11:49 pm, barichard...@gmail.com 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
[quoted text clipped - 25 lines]
>                 }
>         }

> if I then try to reference
> the information in the first row
I suspect the code is wrong.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.