JTable: how to select columns at runtime - java

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.

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.

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

There isn't a standard way, however what you could do is something like this:
Use a custom table header render component to install additional actions/UI on the column headers (e.g. through a context menu of checkboxes)
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
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.

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).

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.

Related

How to make a table refresh in an Eclipse plugin?

I have developed an Eclipse plugin, when I clicked the button a table appears on the view. However, this table does not refresh itself, when I click it again or when I a run operations on the table (such as deletion).
While I was implementing my table, I used TableColumn to create my columns and "TableItem" for the rows and values. Therefore, the "TableViewer"s refresh or remove functions does not work.
My table is able to appear, when I click the button and I call this function in the handler, such as;
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView("ViewID");
However, still I am not able refresh it. Any help would be nice.
Thanks!
Basically, you need to call viewer.update() whenever you want to refresh or update the table. SWT tables and JFace viewers does not have a way to monitor the data model.
Alternatively, you can use Eclipse Data Binding to bind the model and the controls/viewers together. Have a look at this entry level tutorial to get you started.

How to restrain checking single checkbox in multiple columns in Jtable

I am trying to implement a Jtable which includes three check-box tables like this:
Can you tell me how to set a single selection group of checkboxes which only allows 1 selected check-box in a single row at any time?
I know of nothing out-of-the-box for doing this. I´d have a TableModelListener check these columns every time a change is made and call setValueAt on the checkboxes as needed.

How can i customize a dialog box in GMF?

Hi,
I am doing a project in GMF. I want to customize a dialog box with a set of default values under the "Choices" column. This is a dialog box which contains a set of values on the left side (Choices), that can be selected to the right side (Feature), and can be moved up or down. Kindly help me..
Thanks in Advance.
Create a class extends to jface Dialog, implement the methods for configuring the shell and create control where you can create composite with two columns in which 1st column will have your default value column "Choices", you can use tree viewer or table viewer according to your requirement. On the selection of content in tree viewer activate the 2nd column composite. You can even use pagebook, A pagebook is a composite control where only a single control is visible at a time.

Disable particular rows of a JTable

I would like to "grey out" particular rows of a JTable so that they may not be selected by any means. The other rows should still be selectable. How do I accomplish this?
You can either override JTable.changeSelection() to deselect the offending row whenever it's selected, or provide your table with a custom ListSelectionModel where you override setSelectionInterval(), addSelectionInterval(), etc. to prevent the row from being selected in the first place.
You will want to create a custom TableCellRenderer, one that will display "disabled" information greyed out. Read the Swing Table Tutorial for more on how to create these renderers, especially the section, Concepts: Editors and Renderers.
Create a temporary TableModel which has only the rows that you want to select. After the selection made and when you want to revert, change back to original TableModel

Filtering a ListView in wicket using 2 drop down boxes

I am trying to filter a list that is placed into a listview through the use of 2 drop down boxes.
The first dropdown box is titled price and the second is owner.
I want to be able to select a value in one or more of these drop down boxes and then have the List view re-render with the filtered results.
The trouble is I do not know how to begin this task, would someone be so kind as to enlighten me :D
Thanks in advance!
Your best starting point is probably this example: (Source code also available on this page, ChoicePage.java is the name)
First of all, you have to use a dynamic model in your ListView that generates the list of items depending on what you had selected in the dropdown boxes.
Then the basic idea is that you add an AjaxFormComponentUpdatingBehavior to the components that control the updates (your two dropdown boxes in your case), and in the onUpdate() method of this behaviour you should add the component you want to update to that AjaxRequestTarget passed.

Categories