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.
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.
Joined: Mar 22, 2004
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!