It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Creating simple AWT grid component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Creating simple AWT grid component" Watch "Creating simple AWT grid component" New topic

Creating simple AWT grid component

Adam Ratcliffe

Joined: Aug 04, 2000
Posts: 13
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,
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
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.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

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...


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Creating simple AWT grid component
It's not a secret anymore!