Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hide rows in a JTable

 
Mikasa Jaeger
Greenhorn
Posts: 24
Chrome Google App Engine Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable and I Want to hide rows of it.

I cant delete and add the rows, need to hide it.
I dont know how to do it, can I set the row size to 0 or there is a method to hide it?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The table pulls the data from the backing model. The easiest would be to maintain a sub collection of hidden data elements.
Hide a row -> move element from backing model to sub collection
Show it back -> move to backing model

However, if you insist on avoiding this easy approach, check out the RowFilter http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting
Note: Row filters were introduced in 1.6
 
Mikasa Jaeger
Greenhorn
Posts: 24
Chrome Google App Engine Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!

I'll try the sub collection first!
 
Mikasa Jaeger
Greenhorn
Posts: 24
Chrome Google App Engine Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I move a full JTableModel to the sub collection and then move it again?

Im doing:




What I want to do is show the empty table to add other special lines and only the special lines are shown when we are adding. But then, that lines are added to the above and it show all together.
And I dont know how to add the entire m_jTableModel2 to m_jTableModel like m_jTableModel += m_jTableModel.


Sorry for my bad english and explanation.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend you go through http://docs.oracle.com/javase/tutorial/uiswing/components/table.html with special emphasis on the section title "Creating a Table Model"
 
m Korbel
Ranch Hand
Posts: 174
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do is show the empty table to add other special lines and only the special lines are shown when we are adding. But then, that lines are added to the above and it show all together.
And I dont know how to add the entire m_jTableModel2 to m_jTableModel like m_jTableModel += m_jTableModel.


- don't to use one or more XxxTableModels for this job,

- probably JTable isn't notified that underlaying model is changed to another JTable.setModel()

- there are two ways

1. use RowFilter (proper)

2. override and to set number of rows in getRowCount (hacky)

- if there are two states only, then to add Boolean as last column, you can to hide this column in JTables view by JTable.removeColumn(int) in RowFilter you can to put value true, false, null
 
Mikasa Jaeger
Greenhorn
Posts: 24
Chrome Google App Engine Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How I filter with a boolean? Do you have any code example?
 
Mikasa Jaeger
Greenhorn
Posts: 24
Chrome Google App Engine Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched and I found this



But mi problem is I dont know how to use it.
 
m Korbel
Ranch Hand
Posts: 174
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are two ways

1. use String "true"/"false"

2. see OP has the similair issue with RowFilter, ended with wrong decision, because works

3. best of description about RowFilter is in official Oracle tutorial, How to use Tables
 
Mikasa Jaeger
Greenhorn
Posts: 24
Chrome Google App Engine Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have this:




But I't show an error:



When I want to apply the filter:

 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please to re_read my point

3. best of description about RowFilter is in official Oracle tutorial, How to use Tables

EDIT

note be sure that in this contex (your wild shots to the dark as an question) nobody knows what do you talking about
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic