• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating simple AWT grid component

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

reply
    Bookmark Topic Watch Topic
  • New Topic