• Post Reply Bookmark Topic Watch Topic
  • New Topic

Table & Drag,Drop  RSS feed

 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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...
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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
  • 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.....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!