• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Problem with TableModel, CellEditor and CellRenderer

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
now I tried a long time to implement an JButton in a JTable-Cell.
I know that I've to write a CellEditor and a CellRenderer, and may be a TableModel.
I read the Swing-Tutoriel from Sun, but I really have problems with it. I looked in the examples but I doesn't understand it.
How is a CellEditor, a CellRenderer and TableModel built up?
What I've to do, to realize what I want?
How I implement what I've created?
Based on some examples I tried to rebuild the editor on my own :

Do anyone knows some other good sites or tutoriels about this?
Greetx
Lars
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lars,
I will do more than give you an example page. I can point you to some code that does exactly what you want!
http://www2.gol.com/users/tame/swing/examples/JTableExamples2.html
Regards,
Manfred.
 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
first thanks for the link.
I take the example an tried to rebuild it, but I've now another problem. I tried to put Images and JButtons together in the JTable.
Either I can the image or I can see thew Button, but not together.
What I'm doing wrong.
Here the code of my AbstractTableModel :

Greetx
Lars
 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
is it possible to combinate two differen CellRenderers? For example a ButtonRenderer and an ImageRenderer???
Regards
Lars
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lars,
I would say, it is. I have not done it, but you seem to be looking in the wrong place. As I see it, the example I pointed you to does this:
table.getColumn( "Button" ).setCellRenderer( new ButtonRenderer() );
There should be nothing to stop you from doing the above and the following:
table.getColumn( "Image" ).setCellRenderer( new ImageRenderer() );
Each renderer should implement getTableCellRendererComponent and return itself after setting somethings.
Regards,
Manfred.
 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manfred,
thanks for your help, it works! The table is now showing images and buttons
But i've another last question, sometimes the table shows the text, not the buttons. What can be the reason??
Regards
Lars
 
reply
    Bookmark Topic Watch Topic
  • New Topic