• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable, setValueAt losing my centre render

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a JTable, I used a DefaultTableCellRenderer in order to set the values at the center of each cell.
After I created the table, the values really were in the middle of each cell.
The problem is that when I use setValueAt, the parameters I changed won't be at the center anymore, but they will become left aligned.
My question is, how do I update a cell value AND keep the date at the center of each cell?

Thanks for the help!
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Changing the data in the TableModel (using the setValueAt(...) method) has no effect on the alignment of the data in the renderer.

Some other piece of code is causing the table to lose the custom renderer. Or if you implemented the setValueAt(...) method yourself you are invoking the wrong fireXXX(...) method.

Post a proper SSCCE that demonstrates your problem.
 
Yakir Levi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.
Here is my code:
This is the panel that creats and holds my table:


This is my table model:


And this is how I try to update the data in the cell of the table:
In another class, I created an instance of RamPanel, and named the variable that holds that instance in the name "table". This is the method that treid to update the data in the cell:


Thanks for the help.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
Please read the SSCCE link in Rob C's post. Have a look at the Java™ Tutorials section about tables; that might help you. I have forgotten just about everything I ever knew about tables.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the future make sure you post a proper SSCCE. That means simple code in a single class that we can copy/compile and test.


Your custom getColumnClass() method simply returns the class of the data to determine which renderer to use.


However the data you add to the model is String data, not Integer data, so the String renderer will be used to render the column.

So the problem is with your data, not the method.

If the String data is indeed a number then you first need to convert it to an Integer before adding it to the model.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic