Forums Register Login

JTable with JLabel in cell renderer problems

+Pie Number of slices to send: Send
Good evening!
I have a JTable with a JLabel where i show a given picture if a person is approved(or failed) in a test.
I use that renderer:
It works flawless, until i have to edit a Student in a JTable row.I open a screen with the contents of that row for edition.Of course, my Table model dont show a value, but a JLabel where i show the picture.But in my Edit frame, i have a box with values.I tried to update after i choose a value but dont works(off course, if i close the main frame and open the imagem is showed modified, but i need to show the rows updated after i close the edit frame(NOTE: all other fields i change in Edit frame updates, less the JLabel).I tried that:

but dont update the picture.Any thoughts?


Best Regards,
+Pie Number of slices to send: Send
Just an unrelated hint:

Paul Hayabusa wrote:


Can't you just replace that with one line?
+Pie Number of slices to send: Send
 

Can't you just replace that with one line?


Yeah, you are totally right, a big overwork on my part.

I still can t change the JLabel after edit(only when i close the frame and reaopen again), if you have any thought about it how to do it i will apreciate.


Best Wishes,

+Pie Number of slices to send: Send
Another improvement you might like to make is to extend DefaultTableCellRenderer instead of JLabel. The class has a couple of optimizations that you can read about in the API.

You may need to play with the notifications from the table model (fire.... method calls) ... are you using a DefaultTableModel or do you have a custom table model?
+Pie Number of slices to send: Send
Darry, i use my own TableModel(extending AbstractTableModel).

And i return a JLabel there:

I was trying:


But update everything but the JLabel with my Icon...

+Pie Number of slices to send: Send
Hi Paul Hayabusa,

You need to use a table cell editor in addition to the renderer.
+Pie Number of slices to send: Send
Nam Ha Minh,
how i implement that Editor?


Best Regards,

+Pie Number of slices to send: Send
 

Paul Hayabusa wrote:
how i implement that Editor?


Similar to the renderer. Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender
+Pie Number of slices to send: Send
 

Similar to the renderer.


I read that tutorial to make my renderer.And works flawless if i dont edit my row.I dont get it with the Editor.I will put the same way i made in my TestCellRenderer checking the values for getPoints()?Can you give a snippet of code?


Best Regards,

Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1339 times.
Similar Threads
Pasting image in JTable cells
JCheckBox in JTable
JTable
placing a gif file inside a cell in JTable
Adding images in JTable
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:45:57.