Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table & Drag,Drop

Status
Not open for further replies.

kohinoor2007

Programmer
Mar 21, 2007
69
0
0
DE
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.

Thanks...
 
1) In your own Model, you may generate Methods up (), down () etc., and move those Vectors around.
getValueAt (row, column) shall return the new Values (the old values at new Position) and you're done.

2) Why do you make your Dialog modal, if you like to drag text from it?
Modal Dialogs are annoying.



don't visit my homepage:
 

1)Then I should be having methods like addrow() & deleterow() for adding a new row and deleting one, & making corresponding addition & deletion in the vector.Right?.

When I select one row in the table.How will I get the row index.

2)Okay,If the dialog is not modal,Is drag & drop possible between 2 windows.
 
1) Your object is a JTable.
So you look into the javadocs for JTable.

You're interested to get the selected Row.
So you look for a 'get'-Method, and here you are:
public int getSelectedRow()

Returns the index of the first selected row, -1 if no row is selected.

Returns:
the index of the first selected row
The first selected row? So multiple selected rows are possible? Perhaps you like to make usage of this feature and move multiple Rows up or down?

don't visit my homepage:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top