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 / GUI / October 2006

Tip: Looking for answers? Try searching our database.

How to display buttons in a TableCellRenderer?

Thread view: 
David Lee Lambert - 20 Oct 2006 13:35 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.  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



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.