• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Newly added JTable column does not sorting

 
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JTable And a table model which is working fine.When i click table header it do the sorting also. But after that I added a separate column using TableCellRenderer . The problem is my newly added column (Concept column) does not sorting .

This is my table class



And this is the way That I added my new column in same class.



and this is my ConceptFixValueTableCellRenderer class.





when I debug my program I found that,

In my table model class following method runs only for first 3 columns.It doesn't get concept column.Any one has answer for this question?



 
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't say much looking at the code snippets you have provided. But, you can try this and see what happens:

1. Replace public Class getColumnClass(int col) code with this:



2. Here is a link to Oracle's Java Swing tutorial on JTable. It has a topic titled Sorting. Take a look at it and see if there is anything useful for your application: https://docs.oracle.com/javase/tutorial/uiswing/components/table.html
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prasad Saya,
The problem is my new column is not goes to method as an argument ? It skips that. I can't figureout the reson for that !!!  
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what the problem is. But, the following might help in finding what the issue is.

Try to test the table with just one column only - Concept column. Try to show the data in the table with -and- without the renderer separately.

Also, tell some details like what is the data type of the Concept.  How are you creating the table model? I am guessing the model is extended from the AbstractTableModel. And, use the getColumnClass() as I had shown in my earlier message, for the tests.

 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is in my table model there is a method call getValueAt(int row, int col).here is that:



but my 4th column (concept column) is shows String type data, Accroding to my rendering class



But this shows data in the concept column perfectly. but it can't sort.

Another problem is when I put this conceptValueString in getValueAt() method in table model it also shows the data as previous way it do the sorting too.but the problem at that pont is, it doesn't shows the tool tip.

Prasad Saya, hope these informations are goog enough to understand my problem. And I use the AbstractTableModel in my table mode.
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the data type of the Concept column?
What is the cell renderer used for? Is it used for the concept column?
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:What is the data type of the Concept column?
What is the cell renderer used for? Is it used for the concept column?



data type of the Concept column is String and I use cell renderer for concept column and I'm using the ConceptFixValueTableCellRenderer which is created by me by extending DefaultTableCellRenderer class.
I added my ConceptFixValueTableCellRenderer class in earlier.
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the cell renderer used for?
What is the purpose or functionality (for example, once I had used the cell renderer to make a new background color for a particular table column cell)?
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:What is the cell renderer used for?
What is the purpose or functionality (for example, once I had used the cell renderer to make a new background color for a particular table column cell)?



In previously I had 3 columns only in my table.(without concept column) Then I need to add the concept column and tooltip to the each cell in concept column. To draw that new column I used cell renderer
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the cell renderer for this column just to show the tooltip?
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:Is the cell renderer for this column just to show the tooltip?



Not only to set tooltip also set the Text of the column too
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since a custom renderer is used to render the cells one has to use javax.swing.table.TableRowSorter and then set a custom java.util.Comparator for sorting. Here is the Oracle's Swing tutorial for that: https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:Since a custom renderer is used to render the cells one has to use javax.swing.table.TableRowSorter and then set a custom java.util.Comparator for sorting. Here is the Oracle's Swing tutorial for that: https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting


Hey ,
I found the problem of here.In my method I declared column value as the row value (fixValue). So then method in my rendering class gets object value as that fixValue and then get some strings and set that value in the column and the tool tip too.

So I can't sort that column according to the string value here.Because it returns all the row value. So whta Can I do here is set the relevant string in the (column no 3) and then pass that string to renderer class.then just set tool tip only.No need of set text here.Because I set value in model class



Just these 3 lines. Simple !!!  



 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic