TableView enhancements for JavaFX 2.2
Jonathan Giles
jonathan.giles at oracle.com
Wed Mar 7 13:23:28 PST 2012
Yes - as columns and rows change positions, their indices will have to
change too.
Depending on the use case this may be fine. Basically some people will
want to style columns and rows based on the index the cells find
themselves in, whereas others want to style rows and columns based on
the content the cells contain. Unfortunately I don't have a strong gut
feeling on which is the more common use case. The approach I'm
suggesting here is perfect for the former use case, but terrible for the
latter. I'd love to hear an idea for the latter approach though, and it
may entail the kind of approach you mention where it is left up to the
developer and their cell factories...
-- Jonathan
On 8/03/2012 10:18 a.m., Daniel Zwolenski wrote:
> I like the idea of being able to style cells (will have a look at the
> other changes later) but might not the index option run into trouble
> when you start adding/removing rows/columns? Row 5 becomes row 4 when
> you delete row 2, so the developer will have to manually adjust the
> styles.
>
> As a side note, currently I do this sort of styling by using a custom
> cell factory and adding a style class on the cell as needed in the
> updateItem method (or in a listener that holds onto the reference to
> the cell). Seems to work well enough - apart from the issues with
> adding/removing styles but that's a separate issue.
>
>
> On Thu, Mar 8, 2012 at 7:09 AM, Jonathan Giles
> <jonathan.giles at oracle.com <mailto:jonathan.giles at oracle.com>> wrote:
>
> Yes, this is true, and I heard it mentioned today elsewhere too.
> So, there has been talk for sometime about validation APIs, etc,
> and this may one day be applicable, but there is also a simpler
> way that we could do in 2.2. We could just add a styleclass to
> each row in the TableView visible area that represents its index,
> and have both column and row styleclasses in the TableCell. I'll
> have to check with David, our CSS guy, on how much of a heart
> attack this may give him though.
>
> For example, the third column of a TableView might be column-3 (or
> column-2, I'm not sure if we should count from zero or one), and
> the third row might be row-3 (or row-2). I would then possibly
> also have the TableCell include both style classes, so that you
> could write something like:
>
> .table-cell:column-3:row-3 {
> -fx-background-color: red;
> }
>
> If you wanted to fill all cells in the 5th column with a green
> fill, you could do:
>
> .table-cell:column-5 {
> -fx-background-color: green;
> }
>
> And, of course, if you wanted to fill a row with a blue fill, you
> could do:
>
> .table-cell:row-10 {
> -fx-background-color: blue;
> }
>
> I think this might be a little painful initially, but when
> combined with a future validation API that knows explicitly about
> TableView and its styleclass approach above, you could get some
> cool stuff happening fairly simply.
>
> -- Jonathan
>
>
> On Thursday, 8 March 2012 10:02:02 a.m., Tom Eugelink wrote:
>
>
> Wat would be interesting is to be able to indicate that a cell
> as an error, maybe by showing a red border. Or by some overlay.
>
>
More information about the openjfx-dev
mailing list