Avatar of sargent240
sargent240
Flag for United States of America asked on

Java programming

I am setting up a table in java and it starts with a blank row.  When I go to add my data the first row is always blank.  How do I correct that.  I'm not sure what code to attach so if someone sees some code I have not attached I will do so.  Thanks.

    String homePlayerData[][] = {{"", "", "", "", ""}};
    String homePlayerCol[] = {"Number", "Player", "Points", "Fouls"};

    DefaultTableModel homeTable = new DefaultTableModel(homePlayerData,     homePlayerCol);

            while (rec.next()) {
                if (team.equals("home")) {
                    homeTable.addRow(new Object[]{
                        rec.getString("number"),
                        rec.getString("name"),
                        rec.getString("points"),
                        rec.getString("fouls"),
                    });
            } else {
                    visitorTable.addRow(new Object[]{
                        rec.getString("number"),
                        rec.getString("name"),
                        rec.getString("points"),
                        rec.getString("fouls"),
                    });
                }
            }
Java

Avatar of undefined
Last Comment
mccarl

8/22/2022 - Mon
CEHJ

I'm wondering why you're surprised. If the TableModel contains an empty row and then you add (append) to it, then why should the empty row disappear?

I would generally use the Vector type of TableModel rather than Object[]. The latter is for fixed conditions. Also your else-if is odd: you do precisely the same thing in each case

http://technojeeves.com/joomla/index.php/free/59-resultset-to-tablemodel
sargent240

ASKER
The reason I am surprised is because I am trying to learn a little about java programming and am not familiar with a lot of how it works.  I will look at the web site you posted and thanks.
sargent240

ASKER
In the if I write the data to the home table and the else to the visitors table.  Are you saying I cannot set the table up without an empty row?  I'm not certain how the empty row gets there in the first place.  Is it put there because of the way I am setting up the table?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
sargent240

ASKER
I meant to say, are you saying I cannot set the table up without an empty row using the approach I have posted?
CEHJ

I meant to say, are you saying I cannot set the table up without an empty row using the approach I have posted?

There's some confusion here. You can't set the table up without an empty row using the approach you posted because ... your approach uses an empty row.

You can set a table up without an empty row simply by only using filled rows for the TableModel. See the code i posted. Set the resulting TableModel to your table
ASKER CERTIFIED SOLUTION
mccarl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sargent240

ASKER
The first line of your code, replacing the homePlayerData with a zero did exactly what I was looking for and a simple adjustment.  The balance of your code I follow exactly and was a nice touch.  Thanks as usual your a hand my friend.  Cheers
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mccarl

Your quite welcome! ;)