Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JTable with JLabel in cell renderer problems

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Sheriff
Posts: 21802
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just an unrelated hint:

Paul Hayabusa wrote:


Can't you just replace that with one line?
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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,

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul Hayabusa,

You need to use a table cell editor in addition to the renderer.
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Ha Minh,
how i implement that Editor?


Best Regards,

 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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,

 
Good night. Drive safely. Here's a tiny ad for the road:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!