Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-13-2004, 04:03 PM   #1 (permalink)
freesoft_2000
Code Monkey
 
Join Date: Oct 2004
Posts: 51
freesoft_2000 is on a distinguished road
Question Clipboard

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
freesoft_2000 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 01:23 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting