Need help creating a grid.  
Author Message
El Durango





PostPosted: 2003-11-23 17:47:00 Top

java-programmer, Need help creating a grid. Hello I am new to Java AWT/Swing and have a question.
I would like to create a 10x10 grid, where each "cell" can handle mouse
events. So if I click on cell with a coord A4 then it would change color.
I was thinking of using JButtons but I want the "cells" to look more like
Excel-like in appearance. I also found a component called JTable but I do
not think that it can handle mouse events. Any suggestions??


 
VisionSet





PostPosted: 2003-11-23 18:45:00 Top

java-programmer >> Need help creating a grid.
"El Durango" <email***@***.com> wrote in message
news:Lm%vb.22$email***@***.com...
> Hello I am new to Java AWT/Swing and have a question.
> I would like to create a 10x10 grid, where each "cell" can handle mouse
> events. So if I click on cell with a coord A4 then it would change color.
> I was thinking of using JButtons but I want the "cells" to look more like
> Excel-like in appearance. I also found a component called JTable but I do
> not think that it can handle mouse events. Any suggestions??
>

Use a GridLayout on your parent container

parent.setLayout(new GridLayout(y,x,gapY,gapX));

use

parent.add(Component c)

to add a bunch of Components filling the parent, register a MouseAdapter
with each of these and use it to call your Components repaint() after
changing the background colour.
Usual multipurpose component is something like JComponent.

But if you need to handle text in any really useful way then JTable is
probably the way to go.

--
Mike W


 
El Durango





PostPosted: 2003-11-23 19:47:00 Top

java-programmer >> Need help creating a grid. thnx for the info,
I don't need any text it will just be a grid where if you click on a cell it
will change into a random color, kinda like a rubix cube except not the same
game.
"VisionSet" <email***@***.com> wrote in message
news:b90wb.1920$email***@***.com...
>
> "El Durango" <email***@***.com> wrote in message
> news:Lm%vb.22$email***@***.com...
> > Hello I am new to Java AWT/Swing and have a question.
> > I would like to create a 10x10 grid, where each "cell" can handle mouse
> > events. So if I click on cell with a coord A4 then it would change
color.
> > I was thinking of using JButtons but I want the "cells" to look more
like
> > Excel-like in appearance. I also found a component called JTable but I
do
> > not think that it can handle mouse events. Any suggestions??
> >
>
> Use a GridLayout on your parent container
>
> parent.setLayout(new GridLayout(y,x,gapY,gapX));
>
> use
>
> parent.add(Component c)
>
> to add a bunch of Components filling the parent, register a MouseAdapter
> with each of these and use it to call your Components repaint() after
> changing the background colour.
> Usual multipurpose component is something like JComponent.
>
> But if you need to handle text in any really useful way then JTable is
> probably the way to go.
>
> --
> Mike W
>
>