Ste Hutton

Greenhorn
+ Follow
since Oct 08, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ste Hutton

Ranganathan Kaliyur Mannar wrote:Hi,
I looked at the code. Basically, the list is being added to and removed for the table to refresh. So, if you are doing a rollback, call em.refresh() for that entity and then remove that object from the list and add it again to the list. This should refresh the table.



Thanks, I managed to get this working. I just rebuilt the part of the application exactly the same as previous and for some reason it worked.

Strange.

Thanks for your time.
12 years ago

Ranganathan Kaliyur Mannar wrote:First of all, where is the call to refresh()? It should be called whenever an exception occurs and rollback has happened.

More importantly, you need not refresh the entire contents. Just refresh the entity that you are referring to (i.e the one you tried to save and rolled back). And normally, whenever the table data model is changed, it would call its fireXXX methods to notify the JTable to update itself. You need to see if that happens in this case.



I can't figure out whether a fireXX is being called on the JTable, not quite sure how I would go about doing that.

What I did notice though whilst debugging is that the JTable binding is actually an IndirectList which is a separate entity than the List used to originally bind the JTable and this is what isn't being updated.

The changes are immediate in the JTable when editing the JDialog so the property changes on the object being edited must be firing correctly. I've read that it's possible to get the table to redraw by accessing the TableModel and firing a FireTableDataChanged event. The problem is though I can't access the table model because it's in a private class and I get a BindingTableModel cannot be cas't into DefaultTableModel.

Thanks for the replies.
12 years ago

Ranganathan Kaliyur Mannar wrote:Why do have so many calls to 'entityManager.getTransaction().begin()' ?
and you re calling begin even after a 'rollback' or 'commit' is done...

as for the rollback issues, I think you can do a entityManager.refresh for that entity which should then have the correct data which will be reflected in the JTable...



Many thanks for the reply.

I had placed begin where I thought they were needed (not made a database app for some time so a little rusty).

I've altered the code a little but it still isn't updating the JTable to reflect the changes.



the entityManager.refresh(entity) in the for loop is what you were referring to refresh the entity right?

Many thanks in advance
12 years ago
Hi all,

I've been using netbeans to build a database application and it all seems to be working perfectly apart from 1 issue I'm experiencing.

I have a JTable which is bound to a List<> of an entity class inside an entity class. The JTable itself isn't editable, but when you select a row from the list, I pass the object inside the List to a JDialog, where each field is bound to the entity objects attributes. The changes when being made are immediately reflected in the JTable. However if I cancel the database transaction, the database rollsback the transaction. However the JTable remains updated and out of synchronization with the database.

Does anyone know any way around this?

Here is the code I am using to save / refresh the database

12 years ago

Michael Dunn wrote:> so I'm using a custom renderer to display the name of the Customer

instead of using a renderer, create a Customer class where you override
toString() to return the customer's name, then just read the db data into
Customer objects and add them to the comboBox (which will display only
the customer's name).



Hi Michael,

Thanks for the reply, I've tried your suggestion and it worked. Great thinking outside the box, cheers.

Regards,

Ste
13 years ago

Karthik Shiraly wrote:This doesn't seem to be all that simple. It behaves differently in different look and feels - in Metal, the background color is simply ignored for the body but used for the arrow(??) and the list, while in Windows system look and feel, it works fine.
What L&F are you using - what's the OS?
In my Win7 system, I had to just setBackground of combobox to pink; it worked as expected even with a custom renderer and regardless of focus. I didn't need to set background of renderer at all.
But it worked very differently in other L&Fs.




Hi,

I'm using a customer L&F from http://www.jtattoo.net/ which goes by the name of Acryl w/ Win 7. I looked at the source code of the L&F to see how it worked but it was a little too complex to follow for my small brain.

I tried your snippet of code but it still rendered white when not in focus, and the list background was pink (not white).

Thanks for the help though.
13 years ago

Rob Spoor wrote:Call setBackground(...) with a value dependent on the isSelected argument.



Hi,

I tried that but it doesn't give the behaviour I required. Here is my code:



What happens is the combobox appears white on the GUI (i require it to be pink) when it's out of focus. I have no issues with the background of the list, but I am unable to set the JComboBox default colour when its not being used.
13 years ago
Thanks for the reply.

In that case, how would I set the colour of the selected index? Here is the code for my renderer as it stands:



Thanks in advance.
13 years ago
Hi all,

I've got a small problem in my GUI, which I cant seem to fix. Below is a screenshot of my GUI and I wanted all the box background colours to be pale pink, and all the ComboBoxes to look like the Pattern Supplied combo box (Pink unselected and white list items. The problem I have is that the Customer JComboBox is bound to a list database objects, so I'm using a custom renderer to display the name of the Customer. However this is preventing the JComboBox.setBackground() method from working.

I've tried editing the list background in the renderer, - this makes the unselected combobox pink, but also makes the list items pink too. I've also tried overriding paint, and painting the background pink - this also works. However it paints the list pink and prevents list.setBackground() from working, preventing me from making the list background white.



This issue is driving me insane and I'd be extremely greatful if someone who understands this better could help.

Many thanks in advance
13 years ago