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

JTable

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My class x extends AbstractTableModel,then i added
addTableModelListener method to the reference of class x.
In constructor of addTableModelListener i passed the object which implements TableModelListener. whenever i am editing the table and changing the value in the cell the tableChanged method is not fired.Can any body help me in this issue..???
Basically what i want is whenever there is a change in the data
an event should fire...So i went implementing this TableModelListener.So anybody who worked on Jtable can help me in this issue how to go about??
thanks,
selva
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi selvas,
what i understood from your post is that u want to do something whenever u change some value in the table.and if i'm right till now then u want to override the tableChanged(...) method of TableModelListener.
so selvas ,JTable itself implements TableModelListener.so if u override the tableChanged(...) method of your JTable then it will be easier for u.
look and run the following code.

every time u'll edit the table the tableChanged() event will get fired(see console).

was it what u wanted or i misunderstood your problem.
regards
deeksha
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Deeksha,
Thanks for ur imm reply.
This above code will work fine if You pass
array of objects (ie data[][],colname[]) inside the constructor of JTable.But when I pass an object of AbstractTableModel inside the JTable constructor this tablechanged method won't fire when i edit the cell and change the value.
so Please deeksha help me in this issue.
with warm regards,
silva.
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi selvas,
here is the modified program that uses AbstractTableModel.
run/go through it.

regards
deeksha
[This message has been edited by deekasha gunwant (edited February 05, 2001).]
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear deeksha,
thanks for this imm kind reply,this is working fine.This is what i need.
Give me some sugession on JTable.In run time i want some of my rows not to be visible(i.e it will be based on filtering condition).What i tried was to create a new model each time i am doing filtering .Is this right or i need a different approach for this?.Please guide me in this issue.
silva.
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi selvas,
can u give me an idea on when do u want to filter the contents? i mean once u have displayed the data in the table. now do u want to filter the data when some button is clicked or something else is in your mind?
may be that'll help me to suggest u something.
regards
deeksha
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again selvas,
I'd like to ask you one more question.and that is why are u using AbstractTableModel instead of using DefaultTableModel .
the reason being that DefaultTableModel shall be able to provide you i feel almost all functionality that u are looking for.
for example to remove a row from your table u can use
removeRow(int row) function of DefaultTableModel directly.it provides you with inserRow() also.so it can be totally dynamic.
and whatever insert/delete u'll be doing via these methods it will be reflected directly in your table.
in case of your earlier problem of setValueAt() also DefaultTableodel could have taken care of it on its own.
i'm really very curious to know why are u using abstract TableModel instead of using DefaultTableModel
regards
deeksha
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi deeksha,
Here is my requirement.
I want a JTable which has to dofiltering .My header of JTable has a combo box.This combo box should contain only the unique values from that particular column and based on selection of the item in combo box the corresponding rows shouldbe displayed and other rows are not to be displayed.If suppose in the combobox I select the item "all" so now all rows show be displayed in our JTable.This is similar to microsoft Excel application.
So based on this requirement,I took 2 vector one parent containing all data of the table and other the display one .So Whenever an item is selected in combobox i will select the particular row and put into display vector.Here during each time of my selection i am creating an AbstractTablemodel object and passing my display vector inside the constructor and calling setModel method of my Jtable . i.e each time user selects an item i am going to create a table model object.
I got a link from www2.gol.co/users/tame/swing/examples.Based on this started working.
U can suggest me how to go about to acheive my filtering.?
thanks for timely reponse
regards,
silva.
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi deeksha,
Here is my requirement.
I want a JTable which has to dofiltering .My header of JTable has a combo box.This combo box should contain only the unique values from that particular column and based on selection of the item in combo box the corresponding rows shouldbe displayed and other rows are not to be displayed.If suppose in the combobox I select the item "all" so now all rows show be displayed in our JTable.This is similar to microsoft Excel application.
So based on this requirement,I took 2 vector one parent containing all data of the table and other the display one .So Whenever an item is selected in combobox i will select the particular row and put into display vector.Here during each time of my selection i am creating an AbstractTablemodel object and passing my display vector inside the constructor and calling setModel method of my Jtable . i.e each time user selects an item i am going to create a table model object.
I got a link from www2.gol.co/users/tame/swing/examples.Based on this started working.
U can suggest me how to go about to acheive my filtering.?
thanks for timely reponse.
regards,
silva.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Did any one have idea about table filtering and finding
the row according to the criteria(say eventID) given by user.
Suggestions are welcome
regards
Anand
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic