• 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

Table & Drag,Drop

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

I have 2 questions running around my head,which I would like to clear.


[1]I have a table(say 4 columns).It would be populated with datas on loading.
After this Initial loading of the table, may have to add new rows,delete rows,move rows up & down.

I have my own tablemodel as below, extending from AbstractTableModel.

///MyTableModel extends AbstractTableModel

Have seen that only the defaultTableModel has method for adding & inserting rows.It doesnt have any method for moving the rows up or down.

I store my rowdatas & column names as vectors in "MyTableModel".

So How can I add,delete,move rows up & down(1 row up & down).I know that,have to update my Tablemodel & call one of the fire methods.But bit confused about the detailed way.Please guide.

[2]
I have a JFrame,where I have placed a Table.By clicking in one of the cells in the Table,a modal pop up Dialog appears. Is it possible to drag a "text content"from the pop up dialog to one of the cells in the table.

Do I have to call the "setTransferHandler" also in this case.

Thanks...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So How can I add,delete,move rows up & down(1 row up & down).I know that,have to update my Tablemodel & call one of the fire methods.But bit confused about the detailed way.
Look at the source code for the DefaultTableModel class in your sdk/src file. You can get some ideas about how to implement things.
How can I add,delete,move rows up & down(1 row up & down).
You'll have to make up some methods in your table model to do these for you.
I know that,have to update my Tablemodel & call one of the fire methods. But bit confused about the detailed way
DefaultTableModel source code may help with this. Also, look at the class api methods for the classes and interfaces involved (follow the class hierarchy shown at the top of the class api for classes such as DefaultTableModel) for useful methods that you can try/use. Knowing what you want to build and looking through the docs with a little inspiration from source code is the way to build/create new things.
I have a JFrame,where I have placed a Table.By clicking in one of the cells in the Table,a modal pop up Dialog appears. Is it possible to drag a "text content"from the pop up dialog to one of the cells in the table.
I would be wary of using a modal dialog; it could prevent any further action in the drag and drop operation. A non–modal dialog might work okay.
Do I have to call the "setTransferHandler" also in this case.
I think yes, you would need to write a TransferHandler. The tutorial page on drag and drop in the Swing tutorial has enough discussion and example code to get you started. The javadocs are helpful in this, too.
 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Craig,Your reply made me think of taking a different approach.When I looked into the "DeaultTableModel" class,it has everything from addrow(),removerow() & moverow().

S0 "mytableModel" could derive from defaulttablemodel instead of abstracttablemodel...

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