Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner class tableModelPanel cant actualize filtered changes to Jtable

 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know why inner class tableModelPanel  can't actualize outer variable modified by other inner class botonesPanel. I'm using variable totalFiltered as an external variable and both inner classes have acces to it but inner class tableModelPanel dont show any changes when I press TAXI01 button. Please any help.


 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not well-versed with filters, but, simply calling the everytime on toggle click event should work.
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Yeah. To me it's correct but nothing happens.
 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is you are not modifying the filter object referenced by totalFiltered you are creating a new filter object and so you haven't actually changed the filter object the Jtable is using - it is still referencing the original object. You need to do what Ranganathan Kaliyur Mannar suggested and set the JTable's filter after you have created a new one.
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. But where should I put this in my code.


Sorry I'm trying my best. Please help me.
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done what you suggested but nothig happens.  I have added this line 



My code.

 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you expecting to happen when you select and deselect the button?
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm expecting to filter TAXI01 and make JTable show only row's which has TAXI01.
 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you should be calling the row sorters setSortsOnUpdates(true); method when you create the row sorter.
I've tried adding this to your code and it makes no difference - but I believe it is needed to get dynamic sorting/filtering to work.

I found an article which seems to about the same problem you are experiencing, I don't have time to go through it and play with your code at the moment but you can read the article here https://community.oracle.com/thread/2246998 and maybe it will help you solve the problem.
 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just noticed you are creating two tableModelPanel objects: one you are using to display the table and the other (referenced by instancedTabla) you are using to perform the filtering on.
So remove the assignment to instancedTabla and change all references to instancedTabla to panelTable.
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony I'm reading your suggestion. Then we will see whta happens.
 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This definitely is the solution as I have changed your code and proved it works.

BTW whilst changing your code I noticed you should do the following:
1. Use Java naming conventions. Class names start with capital letters etc
2. Format your code consistently - it will help you to read your code and find mistakes such as where you currently add your filter.
3. Before setting the frame to visible call it's  pack() method so the frame sizes correctly.
4. Rather than setting an empty filter set a filter for ".*" so it toggles between displaying all the rows and just TAXI01 rows
5. Get rid of filtersHash or use it as a cache - there's no point in storing the filters in filtersHash if you remove them on every toggle. If you want to cache the filters, fill the filtersHash map when you create the table and don't remove any filters from it.
6. Don't remove the filters from 'filters' in a while loop - if your code is correct there should only ever be one type of each filter in 'filters' and if you want to remove all the filters just use the removeAll() method.
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony I tried what this page say https://community.oracle.com/thread/2246998 but I dont get it.

 

Can you show me modifications in my code ?

Thanks.


 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key to getting your code working is this post:

Tony Docherty wrote:Just noticed you are creating two tableModelPanel objects: one you are using to display the table and the other (referenced by instancedTabla) you are using to perform the filtering on.
So remove the assignment to instancedTabla and change all references to instancedTabla to panelTable.


If you apply this change to your original code and add sorterMyTableModel.setRowFilter(totalFiltered); where you set the new filter it will "sort of" work. I say "sort of" because the code now toggles the displayed rows but not necessarily in the way you want. My last post gives you the remaining details on what needs to be changed.
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony. How you add .

I cant find  a way since I have to use an instance of TableModelPanel. Well my java skills level are not so high.

I just can't use:



I hope you can help me.

 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that code snippet you need to change line 2 to


 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your suggestion was very helpful. Thank you Tony.
 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure. Is it all working now?
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is working like a charm but now I have this question. How can I combined groups of filters. I cant find information on forums about it.  I have created this topic.

Combined groups of filters

I hope you can help me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!