Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating simple AWT grid component

 
Adam Ratcliffe
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to create a simple grid component that provides the following capabilities:
1) Can be constructed with an arbitrary number of rows and columns.
2) Each cell is capable of triggering an event in response to user input in that cell.
3) The entire grid should be able to be overlaid with an image.
As an approach, I'm thinking of extending the AWT panel class and creating individual panels for the cells formed by the rows and columns.
If anyone has done something similar before and can offer comment on this that would be helpful.
Kind regards,
Adam
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
why won't you use JTable (ok, or Table) for this - extending it if necessary. JTable.setBackground() should be able to accept an image (maybe not, try JScrollPane as well). the cells can be edited and the event part shouldn't be a problem.
chantal
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would extend the AWT Panel, Canvas, or just Component classes... does the grid need to appear on top of the image, or does the image just have to have seperate clickable areas? Add a MouseListener to this component, and use the getX() getY() methods of the MouseEvent passed to it to determine where in the grid was clicked... I know that a Rectangle class is in AWT, maybe those can also be used as grid cells...

I'll post some code to illustrate this soon...

-Nate

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic