• 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

Irregular Grid with Three-State Cells

 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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--
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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--
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic