How to get total number of rows in swt.table - java

What i want to do is to get all the tableItems from the selected row. but i have find out that the tableItems are stored in indexes (like in arrary) and not like give row and column and store it on specific cell of table (row, column).
So i have to go through all the next rows upto the end of table and then go through all the rows upto the selected row to get to my required tableItem.
See image for clearance of my question. The coloured row is the selected one. If i want to go from 'a' to 'b' and then 'c' and so on for complete row, i have go through all the next rows.
so now the problem is how can i get the total number of rows present in swt.table

A SWT TableItem IS a row in your Table. You can use it's getText(int index) method to get the contents of the column with index (starting from 0 for the first column) of the selected TableItem.
Therefor the number of TableItems is the total number of rows.

Related

Why does Apache POI read the row which has been manually erased?

I am trying to figure out why the row on excel gets uploaded which is manually erased(NOT Row delete from right click). Here is the scenario:
PS- I have a logic to trace the empty rows. If no of blank == myColumnCount, I skip the row. Somehow the blank count goes at least greater than 0. Hence gets uploaded
I enter the first row data
I enter the second row
I erase the cells manually of the second row
The data remains only on the first row
I save the file and upload it, POI reads the second row as empty row.
I understand the concept of Physical number of rows but confused as to why this scenario returns the row which has no data ?

Does NatTable need a manual refresh after repaintCell?

I have the following code snippet.
int index = getEventList().indexOf(myObj);
SelectionLayer selectionLayer = getGlazedListsGridLayer()
.getBodyLayerStack().getSelectionLayer();
getNatTable().repaintCell(0,selectionLayer.getRowIndexByPosition(index));
When I run the code shown above, the affected cells only get repainted after I click on the table displayed in the GUI. If I comment out that code and use getNatTable().refresh(); it repaints without me having to first click on the table.
Is there a way to have a cell repainted without having to click on the table displayed in the GUI? I would hate to have to call refresh() for a large table where this code may be executed many times.
No you don't need to perform some additional step in order to trigger the repainting. The issue in your code is the usage of wrong index values. You have a grid so column 0 is the row header from the NatTable perspective. I suppose you want to redraw the first column of the body, which is index 1 from the NatTable point of view. Also the row index is incorrect, as you calculate the index in the SelectionLayer but actually need the index in the table, which is at minimum +1 if you only have a column header row.
Actually your code should work by adding 1 on the index if you have one row header column and one column header row in the grid.
getNatTable().repaintCell(1, selectionLayer.getRowIndexByPosition(index) + 1);

JTable - filling table rows sequentially

I have a jtable and one of cell in each row contains combobox. When i select a value from combobox then that whole row gets updated with somme values.
Now i need to fill data in sequentially manner only.
E.g
1) If user selects a combobox in first row then that row gets updated
2) Now if user selects a comobox other than second row then it should give some alert and stop editing the value

Setting Header Row in Itext Table

I am creating a table using itext. Now while setting header row, if I set table.setheaderrows(2) then it sets first 2 rows as the header. But in my case I want only row no. 2 (not row number 1) to be reprinted while table is extended on the next page.
Is there any way to achieve this?
If you only work with a single PdfPTable, you can't define the second row as the header row that needs to be repeated. The trick is to use two PdfPTable instances with the same widths for the columns. The first one would be a single row table for the first header row, the second one would start with the header row that needs to be repeated. If you add two tables to a document, one right after the other, they are glued to each other and nobody will notice that it's not a single table.

Get values of all columns in selected JTable row

so I have a application in which I have a JTable filled with values related to a process list on a computer (so it has things like process name, PID, memory offset, etc). As part of this I want to collect the process name and PID when a user clicks on a row for a certain process--but how do I do this? If I call "table.getSelectedRows()" or "table.getSelectedColumns()" with a row selected I just get one element representing the clicked field's column or row index. Thanks for any help.
You can get the data for each cell in the row by calling table.getValueAt(row, column) once for each column, with 'row' being the selected row index and the 'column' being the column's zero-based index.
Note that this can be somewhat problematic, however, because the user can re-order the columns, and this method references the column in display-order.
The better way to do this is to reference the JTable's TableModel via table.getModel(), and then using the TableModel's getValueAt() method to get the columns in model order (which does not change when the columns are re-ordered in the view).

Categories