freesoft_2000 9 Practically a Master Poster

Hi everyone,

I am trying to do a simple copy and paste function for a jtable
I am sometimes able to copy and the paste function does not work at all. The class i have implements the ClipboardOwner. I am using the default table model as the model of the jtable.

Clipboard1 and Kit1 are both declared above as global values as part of the Clipboard and Toolkit class respectively. TableModel1 is the instance of my default table model and Table1 is the instance of my JTable

Here is my copying function

public void copy (String str1)
{
StringSelection data = new StringSelection(str1);
Kit1 = Toolkit.getDefaultToolkit();
Clipboard1 = Kit1.getSystemClipboard();
Clipboard1.setContents(data, this);
}

Here is my pasting function

public String paste ()
{
String str2 = null;

Transferable T1 = Clipboard1.getContents(Clipboard1);

if((T1 != null) && (T1.isDataFlavorSupported(DataFlavor.stringFlavor)))
{

try
{
str2 = (String)T1.getTransferData(DataFlavor.stringFlavor);
}

catch(Exception e)
{

}

}

return str2;
}

This how i call the the copying function

int d = Table1.getEditingColumn();
int d1 = Table1.getEditingRow();
String str3 = (String)TableModel1.getValueAt(d1, d);
copy(str3);

This how i call the the pasting function

int d2 = Table1.getEditingColumn();
int d3 = Table1.getEditingRow();
String str3 = paste();
TableModel1.setValueAt(str3, d1, d);
Table1.setValueAt(str3, d1, d);

What i want to be able to do is that a person selects the particular cell and clicks a button the entire contents of that cell is put onto the clipboard and
the person clicks another button the entire contents of the clipboard are inserted into the currently selected cell.

Another question i have is that is there a way to retrieve only the selected content of a particular selected cell ?

At this point i am only require string flavor and nothing else and all the code compiles without any errors.

I hope someone can help me

Thank You

Yours Sincerely

Richard West

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.