• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JTable with JLabel in cell renderer problems  RSS feed

 
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: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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
Java Netbeans IDE Opera
  • 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
Eclipse IDE Hibernate 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 Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 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,

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!