• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

GUI: Cut/Copy/Paste/Etc.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Garion Winters
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*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.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic