sargent240
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(homePlay erData, 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"),
});
}
}
String homePlayerData[][] = {{"", "", "", "", ""}};
String homePlayerCol[] = {"Number", "Player", "Points", "Fouls"};
DefaultTableModel homeTable = new DefaultTableModel(homePlay
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"),
});
}
}
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.
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?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Your quite welcome! ;)
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