*
The moose likes Swing / AWT / SWT and the fly likes Hide rows in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Hide rows in a JTable" Watch "Hide rows in a JTable" New topic
Author

Hide rows in a JTable

Mikasa Jaeger
Greenhorn

Joined: Jul 08, 2013
Posts: 24

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

Joined: Jul 26, 2007
Posts: 10171
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Mikasa Jaeger
Greenhorn

Joined: Jul 08, 2013
Posts: 24

Thanks!!

I'll try the sub collection first!
Mikasa Jaeger
Greenhorn

Joined: Jul 08, 2013
Posts: 24

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

Joined: Jul 26, 2007
Posts: 10171
    
    8

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

Joined: Jun 19, 2012
Posts: 154
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

Joined: Jul 08, 2013
Posts: 24

How I filter with a boolean? Do you have any code example?
Mikasa Jaeger
Greenhorn

Joined: Jul 08, 2013
Posts: 24

I searched and I found this



But mi problem is I dont know how to use it.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
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

Joined: Jul 08, 2013
Posts: 24

Now I have this:




But I't show an error:



When I want to apply the filter:

m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hide rows in a JTable
 
Similar Threads
regarding JTable
JTable
JTable Row Deletion
JTable
JTable