Mark Christiaens wrote:
> 
> > I can't even go that far since JTable has its own problems.  Like you
> > mentioned its hard to customize without creating your own component and
> > its also almost useless for data entry.  In general the whole thing is
> > missing so much basical functionality that you end up spending all your
> > time subclassing their components.  Little things like the simplest of
> > data validation (limiting the number of characters entered for instance)
> > require you to write code when it should be basic functionality of the
> > component.
> 
> I'm afraid that isn't true.  The reason why there is no functionality for
> data validation (like entering only numbers) is that a JTable can contain
> in essence anything you'd like.  You could for example make a JTable of
> regular expressions or of names that have to belong to a database ...
> Each of these needs a totally different validation routine.  It's
> therefor clear that this validation should not be directly included in the
> JTable but should be customizable.

Yes it should be customizable but more importantly it should be easy for
the most common cases.  In Swing they seemed to have often decided that
there were many ways to do something so just leave it up to the
programmer
to write all the code.  I think it would have been much better to
provide
some defaults that handle the majority of the common cases so that you
can
just use it 99% of the time and then write code for the odd case that is
strange.

Simple example is the JTextField.  There is nothing for validation by
default.  It would have been good for them to provide a Document that
could handle say a maximum data entry length and a regular expression
the data has to match.  This would be all a vast majority of the code
out there would need but instead I've got to write that first before I
can concentrate on my application.

I could easily argue it would be even better if there was a truely nice
data entry widget that could have display masks and automatic validation
of things like currency and date/time based on localization settings.
This would save everyone tons of coding time, duplication of effort, and
make Swing nice to use.  As it is, its bare boned so welcome to writing
all this yourself!

> The way this customization can be done for a JTable is by using the
> concept of "CellRenderer" and "CellEditor".  A CellRenderer controls the
> way your data is visualized.  For example, if you have a JTable field that
> contains a multiple choice of which the first choice is at present
> selected, the CellRenderer could visualize that by creating a JPanel
> containing RadioButtons.  If the first multiple choice is selected, the
> first RadioButton is visualized as having been pressed.  In the same way,
> if you are entering data, a CellEditor is used as a component that
> receives your input and verifies if it is correct.  If so, the data is
> entered into the datamodel of your JTable and visualised using a
> CellRenderer.  A very flexible system indeed ...

Flexible on paper but complicated and messy in reality.  If you look at
some of the fundamental bugs that are just now getting fixed in JTable
then you've got to realize how screwed up it was (especially for data
entry).  They now have the focus handling at least a bit better where
TAB at the end of a row of columns will take you to the first column on
the next row (had to code around this before since it would just stay on
the last column!) but now if you do any data entry and press TAB, all it
does is accept the change and you have to press TAB again to move. 
Really
nice for the user (in most areas TAB moves to the next data entry but if
you are in a table and have made a change, please try to remember to hit
tab twice).  Complete bullshit!

Simple things like - "How do I change the background color of a cell"
turn
into that you've got to write your own CellRenderer.  Come on!  These
are
basic things that should be *there already*!

-- 
Brad Pepers
Linux Canada Inc.            Home of Linux products in Canada!
http://www.linuxcanada.com   Proud supporter of Cyclades, Red
[EMAIL PROTECTED]         Hat, and Caldera.


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to