aspose file tools*
The moose likes Beginning Java and the fly likes GUI: Cut/Copy/Paste/Etc. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "GUI: Cut/Copy/Paste/Etc." Watch "GUI: Cut/Copy/Paste/Etc." New topic
Author

GUI: Cut/Copy/Paste/Etc.

Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
Alright, yet another problem to tackle. Might not be that bad. Here is the thing-- I am having NullPointerExceptions when im trying to get the cut/copy/paste methods to work for a JTextArea.
I have buttons made for each, and an Action listener, like so...

Now, my m_textArea (is on screen and all) is what I take is causing the error. Is there something you have to do to make the methods work besides just call em like that? New to gui, so just wondering. Thanks a lot! You people are great
matt hooker
Ranch Hand

Joined: Jul 26, 2001
Posts: 46
Hi Garion,
I'm afraid its not quite as easy as that (though its not too difficult either)
You need to define a clipboard object, either local or System, and to implement the ClipboardOwner interface .. among other things.
A good example of using cut/copy/paste is available here : JavaWorld - cut/copy and paste


Its not what you do, its the way you say you've done it.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Matt - No he doesn't. Not for simply cut/copy/pasting text.
Garion - The only thing I can possibly derive from your NullPointerException, since you failed to tell us anything else about the error, is that m_textArea has not been instantiated yet? I don't know. Could you provide more of your code possbily, or at the very least, the exact NullPointerException error. It should tell you which component you are getting that error on.


GenRocket - Experts at Building Test Data
Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
*smacks himself* Yes, I guess telling you what is really wrong would help. Sorry, I was a bit sleepy. Anywhere, first off, here is my entire code...

Well, this is without the copy/paste/cut... I had worked on it a while and was working on Save. Seems to be the same problem. The actual NullPointer occurs at
String fileText = m_textArea.getText();
I think it basically does everytime I try to getText or write using m_textArea, but I'm not sure why. Just let me know what you think.
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
It took me a while to find this one, too.
Change this:

to this:

Essentially, you were redeclaring a local variable called m_textArea in the constructor of SimplePad which was getting instantiated.
However, your member m_textArea was not.
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
It took me a while to find this one, too.
Change this:

to this:

Essentially, you were redeclaring a local variable called m_textArea in the constructor of SimplePad which was getting instantiated.
However, your member m_textArea was not.
Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
Wow. I can't believe I didn't catch that. Thanks a lot, Bill. I'm sure that was my problem with all the other areas as well. Sometimes we just have to remember the basics. Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI: Cut/Copy/Paste/Etc.