File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Creating simple AWT grid component" Watch "Creating simple AWT grid component" New topic
Author

Creating simple AWT grid component

Adam Ratcliffe
Greenhorn

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

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

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

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
wood burning stoves
 
subject: Creating simple AWT grid component