Can i add a button in a jface table row using ITableLabelProvider? - java

As I am having some 8 odd columns in my table, I dont wanna use ColumnLabelProvider. It will be tiresome and lengthy to add colours and all for every column using ColumnLabelProvider. So is there a way to add buttons in a LabelProvider implementing ITableLabelProvider?

Related

How can I render a JList inside a JTable cell?

In three of the columns of my JTable that I have set up I would like to have a list in each cell of the column. I'm not sure where to start on possibly creating a custom cell renderer class if that's the best option? My goal is to list the group names each on their own line in each cell, and expand the cell height as new lines are added. Each group will have an AdmType and Admitted entry, so I will also need to figure out how to add another checkbox to the Admitted column cell for every new Group entry.
This below solution did not work for me, but it clearly worked for the person who posted a screen shot of their success. My problems may be due to how I have my TableModel set up.
https://stackoverflow.com/a/32793088/6867420

How can delete/hide the mid row(5)th row before it listed in jtable

Here i have an 1-10 row is listed in jtable i want to delete/hide the 5th row before it listed in jtable.
i set the rowheight but it affected the cellselection.Is there any way to hide/delete the row without affected the normal flow code?
If i remove the row it will throws ArrayIndexoutofBoundException.
in my project executed means one gui open in that gui listed the some string. In here we can add the more string via Add Button on popup Button
Here what i need is i have to hide the particular string. That string is placed on 1st row.
i need to hide the string from end user.
now u hope understand.
You can use the JTable row filtering support in order to hide certain rows without deleting them from the model. Also see this: How can I filter rows in a JTable?
You can eliminate rows in the table by calling the removeRow() method. If you want to just hide it instead of elimintaing it you need to customize the JTable's model to meet your specs on what to display.
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
using DefaultTableModel with JTable you should be able to use model.removeRow(int row) function to remove A row from JTable. There is no way to hide a row based on index as much as i know. However, If you need to hide and re-show mechanism you need to save the row prior to delete it and Save the removedRow in a ArrayList to re-use them.. Something as follows:
List<Vector>deletedRows = new ArrayList<>();
Vector removingRow = (Vector) model.getDataVector().get(5);
deletedRows.add(removingRow);
model.removeRow(5);

Java Swing set color of rows and columns based on index with defaulttablemodel

I want to be able to do two things:
set colors of rows based on index, so first row is red, second blue,
third green
be able to set color of columns also based on something, be it index
or their names etc, whatever is possible.
I do not need to detect selection change or anything. Could someone tell me how to do that? What methods would help etc? In case the title wasn't read, this is regarding DefaultTableModel in JTables.
set colors of rows based on index,
Table Row Rendering might give you some ideas.
be able to set color of columns also based on something
You can provide a custom render for any column. Then you can add you logic to color the column based on something. Read the JTable API and follow the link to the Swing tutorial on How to Use Table and you will find a section on creating a custom renderer.

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.

Hiding a particular cell grid in Jtable

I am trying to display numbers in the steps of 5,10,15,20 in a Jtable.
In case of 5 the column names will be 0,5,10,15...
In case of 10 the column names will be 0,10,20,30...
In case of 15 the column names will be 0,15,30,45...
In case of 20 the column names will be 0,20,40,60...
Right now I am able to display 5 and what I need is the same structure but by hiding the vertical cell grid between 5 and 10,15 and 20 and so on.After all this I should remove the column names 5,15,25 and so on.Its not merging columns because my cells are implementing JProgressBar and I need it for painting it in different proportions.Like a cell representing 0-5 may be painted from 0-3 or 3-5 or 2-4.And each cell may be painted based on some value like this.
EDIT::Something similar to Multiple - Span cell as in this link text but my need is merging almost alternate cells by hiding the grid rather than using an Array.Thats why I mentioned it as hiding the vertical border rather than merging the cell.
I think the best way to hide what you don't want to see is deleting it.
But If what you want is to hide or make invisible, most of swing components have a method call
setVisible(boolean value)
Here an example how to hide a row(I hope it helps):
http://www.rgagnon.com/javadetails/java-0216.html

Categories