Slow redraw of TableViewer when changing input object - java

In my project, I have a TableViewer which displays about 1k rows of data from database. The ContentProvider is an ArrayContentProvider.
When I change input the List (setInput() on TableViewer object) to another one with the same amount of data, everything is Ok. But when I want to update it with List<T> with different size than the previous one, the application freezes for about 10x the time of changing with same amount of data.
The first list has a size of 1k, and the second list a size of about 960. Execution freezes directly on setInput() method.
Does anybody know why this happens?

I think the reason is that when you set a List with a different size the whole native TableItems are recreated. So to speed up your table you should use a SWT.Virtual style table. With virtual table only the tableitems which are displayed are created. The others are created when you scroll.
See http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java for an example.

Related

How to fire an event immediately a JTable JScrollpane is activated

Just as the title suggests, I built a Java application that displays the results of students. Everything is working fine, however I was only able to display a set number of rows at a time applying some conditions, by using the setMxRows() method of the PreparedStatement object.
. However, I wish to load all the results sequentially and anytime the Jscrollpane is visible, meaning the results have overflown the available space on the JTable, I would get the id of the last row that activated the Jscrollpane and then reload the results where id is less than this particular id. Please how do I achieve this or is there a better way to get around this. I appreciate your answers in advance

How to force RCP to reload the table content

I have this huge RCP enterprise CRM system I'm working on. Last year it was updated to RCP 4.5. Sadly I'm very bad with RCP because I never had to do with the frontend of it... So my question might seem a little bit strange.
Anyways, my problem is:
I have one table window where all the rows all filled up correctly with data. One column has a function, where I can double click on and one other window will open, where I can edit/remove/add data to it. The IDs of the added values are then showing in the main window's table column. (this is working correctly)
The problem: If I open this editor window, edit something (add new values or remove one or more), then click save and close this edit window (it's actually a new tab...) and then going back to this window after the editing, it will show me the state BEFORE the editing... (new values are not in the list, removed one are still on the list) The values are correctly stored or deleted in the DB, only the UI seems to stuck with the old state. I have to restart the GUI if I want to see the correct (and the actual) state.
My question: how can I force RCP to forget the old state for this tab/window and load the data everytime from DB? I tried many things in the saving method of this window (refresh, dispose of), but nothing seems to work...
Are you using a TableViewer or so?. using the tableViewer.setInput(...) again with new data + layout() may solve the problem, buit as #greg-449 said, we need for information on what kind of taale you are using to display your data and how you tell that table where is this data...

JCombobox auto search

I have a java program which keeps records of databases. I have made use of JComboBox for adding data to my db system. I have to initialize more than 10000 string into my JComboBox. I have used keylistener to make my program auto search elements inside JComboBox.
The problem is that it is taking a lot of time to search a single key. Is there a programming technique to make search faster with keylistener for more than 10000 string elements in JComboBox. Should I have to make use of multithreading to keylistener?
Generally:
Never show so much elements at once into a List,Table,ComboBox etc. It makes the program lags and you spent a lot of memory.Maximum items to be shown per time must be <=300.Basically the comboBox its not so good idea a list or table will fit better.
How?
Every time the list shows 300 items,the user can use next button to load the next 300 from the database or previous button to load the 300 previous items.
About Search:
On every key pressed by user you search into database table you have for the 300 or less best fitting the result and then you add them into the List and ComboBox removing the previous items first.
More about search:
If you want you can retrieve all the items matching to search and use pagination for search results.

Using NatTable for large data which is slow to retrieve

I got a question about the NatTable SWT datagrid widget which I want to use to display a huge log file.
As the log file can be several GB in size, I cannot load it in memory entirely. The application should use as little heap space as possible. Thus, my IDataProvider implements its getDataValue method to read a log file line on the fly, with the help of a little caching mechanism and a cache for raw line positions within the file. When opening a file, almost nothing is known about its contents - not even the amount of rows the table will eventually have to display.
This leads to several problems which currently freak me out:
1) I have to estimate the total row count (using average line length) until the file has been scanned entirely and a maximum line count is really known for sure. As soon this is the case my getRowCount method returns the actual, correct number of rows. This seems to freak out the NatTable widget, it loses its current position entirely and jumps to row # 1!
2) When doing something intuitive as double-clicking on the border of a column (to auto-size the column, just like in Excel), my application freezes completely as suddenly ALL rows cells contents is queried using my provider and the whole concept is abused! I did not want anything to trigger a full file read!
Does anybody have some hints for me? The documentation is so little and so bad...
Any hint is greatly appreciated! How can I prevent my application from freezing??
Thanks!
1) Sounds like the selection isn't preserved when you change the row count - a row count change implies a backing data change hence it's probably playing safe and setting the selection to the first row. You could query the selected row before changing the row count and then reset the selection after you change the row count.
2) In order to figure out what the max-width of the column is, the table has to query each value for that cell in every row... Either you have to implement a paging mechanism such that you return something resulting in zero width when the row isn't visible, or you'll probably want to raise a bug against NatTable to request a feature for an auto-resize mode based on only the visible columns!

sorting a JTable using a data vector

I got stuck with a performance problem while writing my program and I need your help! :)
I'm using a JTable to view test results taken from a vector I made and it has 4 columns in it. When I click on a row the details from a saved txt file of that test are shown in a child window. Also, when I click on the columns header the event sends the vector to a function that sorts it according to the pressed column. Every time a new value needs to be entered the sorting function is called again.
My program works fine with a small number of rows. But, when I enter say, 150 rows, every time I enter a new row the Table flicks (the sort probably takes a lot of time), but I have to keep the vector synchronized with the jable because of the "push to view the result" option.
I would really appreciate some help with this.
thanks
You shouldn't have to do any sorting yourself. JTable supports sorting natively, and has the convertRowIndexToModel and convertRowIndexToView methods to go from the view index to the model index and vice-versa.
See http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting.
Use JTable's internal sorter (DefaultRowSorter). Do not re-create the vector which holds the data - use Vector's add() method to add new records. In many years of Java GUI development I haven't seen a single case where I had to keep records in the TableModel sorted. Make sure getColumnClass() returns a proper type, so the default sorter knows how to sort the column, and that is all.

Categories