Link to home
Start Free TrialLog in
Avatar of sargent240
sargent240Flag 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"),
                    });
                }
            }
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of 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.
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 meant to say, are you saying I cannot set the table up without an empty row using the approach I have posted?
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
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Your quite welcome! ;)