Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable with JLabel in cell renderer problems  RSS feed

 
Paul Hayabusa
Ranch Hand
Posts: 45
  • 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,
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java 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: 45
  • 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,

 
Darryl Burke
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: 45
  • 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...

 
Nam Ha Minh
Ranch Hand
Posts: 515
Eclipse IDE Firefox Browser Windows
  • 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: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Ha Minh,
how i implement that Editor?


Best Regards,

 
Maneesh Godbole
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: 45
  • 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,

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!