tags:

views:

53

answers:

5

I have too many columns in a table to display them all at once, and would like to let the user change which columns are visible. How can I do this?

note: It is easy to make the application select columns at runtime. What I am asking is what UI element(s) to add to allow the user to hide/unhide columns at runtime.

A: 

There isn't a standard way, however what you could do is something like this:

  1. Use a custom table header render component to install additional actions/UI on the column headers (e.g. through a context menu of checkboxes)
  2. Add a custom model which you can re-configure to display different items depending on what the user selected through additional actions on the column headers
  3. Do the event wiring/plumbing.

Alternatively: find a custom component that does this. There probably is something out there already: projects like the component library from JIDE would be a good place to look.

+1  A: 

Table Column Manager allows the user to right click on the table header to control which columns are visible.

camickr
interesting, thanks!
Jason S
+1  A: 

If you can import some external libraries, you could have a look to http://swinglabs.org/docs/components/JXTable/tutorial.jsp which supports such runtime modifications.

Sylvain M
great -- I just tried it and it looks nice.
Jason S
good :). This lib is usefull, I discovered when I wanted to find an implementation of a TreeTable, and this one, works fine :)
Sylvain M
A: 

Use TableModel.addColumn(TableColumn) and TableModel.removeColumn(TableColumn) methods to show/hide columns on-the-fly.

You can attach that calls to any other GUI components (for example, make a JPanel or a JTable with a few checkboxes).

Vanya
thanks but that's not my question. It's what GUI to use to allow the user to initiate the process.
Jason S
added the second sentence to the answer. is it more clear now?
Vanya
A: 

Either display a popup menu with the possible columns when user right-clicks the header or implement a small (and light) popup dialog with a checkbox list for selecting the visible columns. The dialog can be opened by right-clicking, by clicking a toolbar button or from a toolbar menu.

Carlos