I'm trying to develop a Java client for an on-line game. One screen of
the client is supposed to show a list of available games, and allow the
user to select one, then join it or watch it. I decided to do this using
a JTable. The first few columns display data about the prospective game;
I want the last column to display two buttons, one of which would perform
the action of joining a game. Accordingly, I wrote my own table model.
getColumnClass() on the last column of the table returns GameInfo.class.
When I create the table, I also do
games_table.setDefaultRenderer(GameInfo.class,
model.suitableRenderer());
where model.suitableRenderer returns an instance of the following class:
class LoginColumnRenderer implements javax.swing.table.TableCellRenderer {
public java.awt.Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row, int column) {
if (value instanceof GameInfo) {
return new LoginColumnRendererComponent((GameInfo)value);
} else {
throw new java.lang.IllegalArgumentException("Not a Game");
}
}
}
getTableCellRendererComponent(), in turn, returns an instance of the
following class:
class LoginColumnRendererComponent extends java.awt.Container
implements java.awt.event.ActionListener {
java.awt.Button b_watch;
java.awt.Button b_join;
GameInfo game;
LoginColumnRendererComponent(GameInfo g) {
game = g;
b_watch = new java.awt.Button("watch");
b_join = new java.awt.Button("join");
add(b_watch);
add(b_join);
invalidate();
validate();
}
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource()==b_watch) {
lj.watchGame(game);
} else if (evt.getSource()==b_join) {
lj.joinGame(game);
}
}
My problem is that the buttons don't show up. Instead, that particular
column of the table is just blank. What am I doing wrong?
Filip Larsen - 20 Oct 2006 16:48 GMT
> I'm trying to develop a Java client for an on-line game. One screen of
> the client is supposed to show a list of available games, and allow the
> user to select one, then join it or watch it. I decided to do this using
> a JTable. The first few columns display data about the prospective game;
> I want the last column to display two buttons, one of which would perform
> the action of joining a game
Perhaps http://www.devx.com/getHelpOn/10MinuteSolution/20425 is useful
to you.
Regards,

Signature
Filip Larsen