I have been researching this for days and have tried everything I have come across, but to no avail. I have built an item checkout system in JAVA using a Derby Embedded Database and everything that I have wanted it to do works great. The only thing I can't get to work is having my table update or refresh the information displayed after the user (A) Adds a new entry in the system due to a customer checking out an item. (B) A customer returns an item and is checked back into the system. (C) The table data is changed/fixed due to a previous user error. Case in point: The user checks out an item using the check out dialogue box, then clicks the check in dialogue box but the new entry just made, does not appear. Closing out of the program and going back into it then shows the new information.
I have a method called loadTable() that makes the DB connection all the way through building the table how I want and returns the table.
So far I have tried:
- Calling the loadTable() on any event (Button pressed, window closed, etc).
setFireTableDataChanged() method.
table.setModel(), here I tried inserting the loadTable().getModel or using a temp table.
jtable.tableChanged(new TableModelEvent(jtable.getModel())).
SwingUtilities.updateComponentTreeUI(yourJScrollPane); Ultimately it gets added to JSP.
table.UpdateUI();.
((DefaultTableModel)table.getModel()).fireTableDataChanged();.
repaint().
revalidate().
So far everything I have tried, does not produce the desired results.
I know you all will want to see code, there's a lot so I don't know what I should start with. This is my first time posting so, have mercy on me if i'm going about this the wrong way. Many thanks in advance!
Related
When I select a cell and start typing any value it edits the cell.
But when I am sorting few columns(2 to 3) by default using this code below,
natTable.doCommand(new SortColumnCommand(sortHeaderLayer, i, true, sortColumn.getSortDirection()));
and then select cell and start typing for first time or maybe first few times it edits then it won't.
When I debug the code I found that I was getting the selected Cells as empty after few successful editing, and that happens randomly like sometimes after 1 or 2 or 4 .. successful editing, then the selected Cell becomes empty. The cell is selected and is clearly visible but still we get empty in the code.
ActivateEditorAction.run()
The above code is used for the Action for the cell editing on selection. In the else block of the synchronized block when we are checking for isSelectionAndTypedKeyValidForEditing(), there the selected cells is coming as empty, not always but once it starts coming as empty then it keeps on coming as empty all the time even though selection is visible on the table.
Code for the function isSelectionAndTypedKeyValidForEditing()
There are certain events that cause a selection clearing. By default sorting is causing such an event.
If you are using GlazedLists you should also be aware that there are multiple events that are fired in case of sorting. The GlazedListsEventLayer tries to squash those events to a single event, but for huge lists it can happen that still multiple events are fired if the time frame in which GlazedLists is firing events is longer than the squashing time.
Maybe you are hitting a concurrency issue somewhere. There is not enough information about your NatTable setup and too much custom code that overrides the default configuration.
Apart from this information it seems to be a quite specific issue that depends on your configuration and your custom code. And that seems to be much more complicated than to be solved easily via Stackoverflow. IMHO you need professional support in this area. Some project members offer sponsored support in that area.
I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).
I have created a JTable using GUI Builder in NetBeans. It is Currently Having no data. The table is editable, and is Displayed in on a Panel. This Table is called passengerDetailsTable. Now I want users to Write data in its cells and after entering data, when they press submit, data should be extracted from table and available for processing. But I am unable to do it.
I have written sample code to do above:
TableModel tm = passengerDetailsTable.getModel();
Object o = tm.getValueAt(1,1);
System.out.println(o.toString());
This code is triggered when I press submit button.
According to me It should print the value at cell(1,1). But it gives Null pointer exception. Please help me to resolve it.
Now I want users to Write data in its cells and after entering data,
Did the data get saved to the model?
See Table Stop Editing for a way to make sure the data is save when you click a button.
If this doesn't help then post a proper SSCCE that demonstrates the problem because we don't have enough information to keep guessing what you might be doing.
I am a doing a project on Exam Suit in Netbeans swing java application. I have done all my work like login page, sign up page etc etc. But the main problem stick with exam page. I have inserted all the question and there choices with answer(not shown) in a database. I have designed one frame, 1 label for question and three radio buttons for choices and an OK button to select the choices and NEXT button to goto next question. I can easily get the data from database of only one row. But to get the other question I should keep the code in NEXT button, but this can be done only one time. I just want to change the data from table dynamically on click of NEXT button. I am unable to do this, Please help me. Thank You.....
Since your program acesses a database, I assume that you are using ResultSet from JDBC. You need to call ResultSet.next() each time the user clicks on the "Next" button. As long as you keep a reference to the ResultSet, you can call this method until you reach the end of the data set.
I want to refresh the JTable data by clicking a button.
The problem is that the old data in the JTable can't be removed and the new data are just added into the table. I tried below ways to remove the old data but none of them works.
1. table.setModel(new DefaultTableModel());
2. ((DefaultTableModel)table.getModel()).setRowCount(0);
3. ((DefaultTableModel)table.getModel()).fireTableDataChanged();
4. ((DefaultTableModel)table.getModel()).getDataVector().removeAllElements();
5. table.repaint();
6. model = (DefaultTableModel)table.getModel();
while(model.getRowCount() > 0) {
model.removeRow(0);
}
Having a refresh button for a JTable is very suspect. It makes me think you aren't correctly adding data as JTables should refresh everytime data is added or removed.
I would verify a couple of things when using a DefaultTableModel:
Make sure to only add data using addRow
Data should only be inserted using insertRow
Remove data using removeRow
Never modify the internal vectors directly. It won't cause events to fire and you're stuck with a refresh button. I don't know why they even expose it. The JavaDocs should at least specifically warn against this.
If all else fails, fire up a debugger and see what happens.
More of your code might be appropriate here. Hard to tell exactly where you're calling these methods and the order. If you change the model and then call fireTableDataChanged() it should work....assuming you've updated the right TableModel. There is a good Java tutorial for using tables: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
Had the same issue myself, but my solution was different. After checking just about everything, I checked the contents of the table via the console, and found that the contents were indeed being updated. However, the update was not being reflected on the table which was visible on the screen.
In fact, this code:
model = (DefaultTableModel)table.getModel();
while(model.getRowCount() > 0) {
model.removeRow(0);
}
Did not only remove the rows, but also removed the table.
My solution was to remove the table from the form and then re-add it, whenever the table data was changed.
Seemed in my case there was nothing wrong with my coding to generate the table but that the layout manager didn't like overwriting or updating a component the area where I wanted to put it already had something in there.
Something weird going on methinks but at the end of the day this worked for me.