aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Irregular Grid with Three-State Cells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Irregular Grid with Three-State Cells" Watch "Irregular Grid with Three-State Cells" New topic
Author

Irregular Grid with Three-State Cells

Dale Seng
Ranch Hand

Joined: Mar 22, 2004
Posts: 275
What swing components should I use if I wanted to make an irregular grid like this:


So I would have 72 "cells" in the above example. Each cell would need to have three states (let's just say blank, check-mark, and "X").

I'm Swing-challenged, but know how to code otherwise. I plan to have full 'undo/redo' functionality, which I'm sure won't be a problem, but the graphical bit has left me with no known good starting point.

Also, I'd like to enable the user to drag and drop "blocks" on one axis and have the other axis re-arrange itself (some day). So if there's something to do now that would allow that in the future, that would be great. Here's after the user dragged the (i,ii) group to a new location:



I didn't know if you could subclass a Checkbox to get another state, or if a JList would be good or not. My application doesn't really fit a typical checkbox, so maybe that's not the right approach. I thought about drawing my own grid or set of rectangles, then calculating where the clicks happened, but that seems like sort of a low-level starting point.

I didn't have this idea until just this second, but this is looking a bit like "battleship" or "minesweeper". I'm off to find an example, but still, if you have any ideas, please advise. Thanks.

--Dale--
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Sounds like you want a TriStateCheckBox. You should be able to find an implementation on the internet. Then you want a JTable to display the grid. You�ll need to implement an implementation of TableModel - sublassing AbstractTableModel or DefaultTableModel shold be easiest. Your getValue() method needs to return an appropriate TriState object depending on your domain (the simplest would return Boolean which could be null Boolean.FALSE or Boolean.TRUE). You will also need to create a TriStateRenderer and register it with the JTable.
This approach will be able to support drag and drop in the future.

Hope that makes sense. If you�re new to JTables I suggest you work through the JTable trail on the Sun site which is very informative, about an hours work tops I think.

Don.
Dale Seng
Ranch Hand

Joined: Mar 22, 2004
Posts: 275
Thanks Don.

I got a nice set of tri-state checkboxes going, but I decided to leave this one to the Swing professionals (or maybe not so professional) at rentacoder. I added a lot of detail to the spec and put it up there. The top an bottom bid had an order of magnitude difference! We'll see what I get back!

--Dale--
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Irregular Grid with Three-State Cells
 
Similar Threads
Layout Problems
Network Simlulation...
want to display the following output?
Layout problem
Sorting ArrayList