|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
Add a 'Total's' row to a FunctionListI have a FunctionList that creates new Objects based on a GroupingList, and a JTable that displays the results. I'd like to add a 'Total' row at the bottom of the table that adds up the values in each column, is there a way to do this?
|
|
|
Re: Add a 'Total's' row to a FunctionListI don't think there is a generic solution for this. But I've created in
the past a TotalizingList which is very similar to the FunctionList. In short this TotalizingList 1) maintains a copy of the original source list as an extension of TransformingList 2) creates an extra object "the total" 3) size() == source.size() +1, and also adjust get(int) ... 4) defines an interface Totalizer which defines an addToTotal method and removeFromTotal method called when objects are inserted or deleted (update == delete of old + insert of new) 5) on listChanges -> delegate to the totalizer function and broadcast list changes as source list changes + last row also updated. Gerrit Dan MacLeod wrote: > I have a FunctionList that creates new Objects based on a GroupingList, and a > JTable that displays the results. I'd like to add a 'Total' row at the > bottom of the table that adds up the values in each column, is there a way > to do this? > -- -------------------- Marble Consulting ---------------------- Gerrit Cap http://www.marble.be/ OO Solutions Engineer mailto:Gerrit.Cap@... Marble Consulting gsm : +32 475 72.94.36 Vinkenbosstraat 13 tel : +32 16 89.50.55 B-3001 Heverlee fax : +32 16 89.50.58 --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Add a 'Total's' row to a FunctionListGL has architecture for computing "calculations" based on List elements. It's new as of about 2 months ago. You can find it in the latest builds, though no screencasts exist for it yet.
This would be the equivalent of Gerrit's Totalizer, though it is intended to assume almost nothing about the value that it is computing (i.e. it might not be a sum... in fact it might not even be numeric). As for how to add these totals into your table, I'd say a custom TableModel is your best bet. It would extend or delegate to an EventTableModel for all data rows, but would report an extra row reserved just for the total information. Since using the GL calculations as the last row in a JTable is a very common usage, this may be code that should be present in the GL core... James On Wed, Mar 26, 2008 at 6:13 AM, Gerrit Cap <Gerrit.Cap@...> wrote: I don't think there is a generic solution for this. But I've created in |
|
|
Re: Add a 'Total's' row to a FunctionListI'm currently using an EventTableModel. If I create a class that extends the EventTableModel how would I tell it to report an extra line?
|
|
|
Re: Add a 'Total's' row to a FunctionListOverride getRowCount() to return 1 more than super.getRowCount();
On Wed, Mar 26, 2008 at 11:34 AM, Dan MacLeod <dan.macleod@...> wrote:
|
|
|
Re: Add a 'Total's' row to a FunctionListSorry to 're-use' this but this is exactly what we have done and it worked ok.
We have recently introduced the use of the EventSelectionModel and GlazedLists.replaceAll method. This is causing a lot of exception when one clicks on the last row of the JTable (the extra row). The EventSelectionModel calls listSelection.setSelection(index0, index1); which in turns checks the size of the list... and of course, the list contains one less element than rows... Unfortunately, EventSelectionModel is final and there is no way to give it a special implementation of ListSelection since it is created in the EventSelectionModel constructor.... HELP!!! Any suggestion? Thanks! Benoit
|
|
|
Re: Add a 'Total's' row to a FunctionListBenoit,
My first thought of approaching this problem is to use a CompositeList like so: EventList myNormalData = .... CompositeList c = new CompositeList(myNormalData.getPublisher(), myNormalData.getReadWriteLock()); EventList myTotalsRecord = c.createMemberList(); myTotalsRecord.add(<an object representing your totals>); EventTableModel tm = new EventTableModel(c, new MyTableFormat()); EventSelectionModel sm = new EventSelectionModel(c); In this way, c is composed of your normal data, and a singleton list containing only a single object that reports your totals. It backs both the data model and selection model, so they both agree on the number of rows. If you want to make the totals row unselectable, you could do that with simple ListSelectionListeners... Does this work for you? James On Wed, May 6, 2009 at 12:15 PM, Benoitx <benoitx@...> wrote:
|
|
|
Re: Add a 'Total's' row to a FunctionListHi James
Thanks a lot for the example. I did not know about CompositeList and it sounds like a much cleaner option. We went down the route of a specific TableModel which also allow us to change the background/font of the last row.. It will be difficult for me to try this soon as it will require a fair bit of change but I will definitely try it. At the moment we simply created our own "EventSelectionModel" and "ListSelection" to fudge the issue of the last row... I know... dirty... but works...time pressure... Once again, thanks for your reply. And a BIG thanks for GlazedLists! Benoit
|
| Free embeddable forum powered by Nabble | Forum Help |