-1

I have Jframe with multiple textfields and textareas , I wanted to add copy paste functionalty to Jtextfields and Jtextareas . as you can see in the picture when I right click on Product Name field , it shows copy paste somewhere else on frame.

https://drive.google.com/file/d/0B2tIFybzjEheNTRUSTB1dTNPdEU/edit?usp=sharing

this is the event i have added to textfield

private void jTextField1MouseReleased(java.awt.event.MouseEvent evt) {                                          
    if(evt.isPopupTrigger())
  {
       jPopupMenu1.show(this,evt.getX(),evt.getY());
  }
}   
  • 1
    Oo god i forgot too add this.Jtextfield1 – user3812293 Jul 09 '14 at 08:20
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete and Verifiable Example). – Andrew Thompson Jul 09 '14 at 09:06
  • I believe I posted MCVE example ,please kinldy check google drive link , I don't how simple can it be more ! – user3812293 Jul 09 '14 at 10:08
  • *"I believe I posted MCVE example.."* For future reference, people typically don't follow links. If it is an MCVE, it can be posted direct in the question. – Andrew Thompson Jul 09 '14 at 10:46
  • Ok Andrew , look at your reputation and mine then think again that I am not much professional like you , please respect begineers on stack over flow , this is my 15th account I am getting banned what a crazy rules over here , are we discussing java or rules of the stack overflow , I am sorry but rules are very annoying here , when people get mad they will not visit this site anymore , they will create another web site like this without rule , rule rule rule rule , just relax a little , see I have pasted a picture on google drive , but the rule of the stack says that you need 10 reputation – user3812293 Jul 09 '14 at 11:00
  • so there is always way to get arround the rules and so finally rules are just annoying people they get mad , relax relax relax , look at mad programmer he is not complaning anything , he just posted and answer , if you dont understand my question , so please study java then \ – user3812293 Jul 09 '14 at 11:02
  • 1
    *"..I am not much professional.."* High rep. on SO does not make someone a professional. *"..this is my 15th account I am getting banned.."* Odd. You say that like it's my problem. *"when people get mad they will not visit this site anymore"* LOL. The rules have recently been *tightened* just to stop the flood of newbie, poor questions that seem to be dragging it into the 'noise' part of 'signal to noise'. If you got banned, then you most likely were asking poor questions. Improve your questions rather than whine about it (is my suggestion). – Andrew Thompson Jul 09 '14 at 11:06
  • I am still not a professional man andrew understand the simplcity of sentences do not complicated , how old are you man ? – user3812293 Jul 09 '14 at 11:07
  • ok my questions are poor man i accept it , but there poor knowledge people arround the world who may need my type of questions understand ? – user3812293 Jul 09 '14 at 11:08
  • how can I improve my questions with getting banned all the time without getting experience of stack overflow and the learn rules tell me , is there a platform for that , imagine you visit my country and you dont know the rules which allowed in your country , should we kick you out of our country in your second day or warn you ? – user3812293 Jul 09 '14 at 11:12
  • god damn i will open another account , if you guys push vote down , dont worry ! – user3812293 Jul 09 '14 at 11:36
  • I believe you're missing the point. You say you need experience and to learn how to use this site better YET you refuse to listen to advice on how to improve your question... You have two options, buck up your attitude and TRY, or get banned again and again till you give up. Your choice! – Troyseph Jun 02 '15 at 08:55

2 Answers2

2

MouseEvents are contextual, that is, the location specified by the MouseEvent is local to the component that generated the event...

Try using...

jPopupMenu1.show(evt.getComponent(), evt.getX(),evt.getY());

instead

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • ok but how add to this to all components on jframe that clicked on , i have created mouse released event on jframe , your code still not affecting the jtextfields and areas – user3812293 Jul 09 '14 at 08:25
  • A `MouseListener` only raises events for the component it is registered against. If you wanted to do this functionality for each component, then you would need to add a `MouseListener` to each component you are interested in providing support for. Around about now, I would be create a custom `MouseListener` class which encapsulated this functionality, create a single instance and add it to each component – MadProgrammer Jul 09 '14 at 08:27
  • do you have some samples ? – user3812293 Jul 09 '14 at 08:29
  • Actually, [this example](http://stackoverflow.com/questions/20598686/jpopupmenu-not-showing-on-the-screen/20598751#20598751) might help – MadProgrammer Jul 09 '14 at 08:32
  • is copy paste functioning like jtextField.getText(); and assigned to global value in a class ? and paste it some where else , and also when i copy something from my jframe is it going to paste to any notepad i opened on windows for example , how to manage that? – user3812293 Jul 09 '14 at 08:44
  • `JTextComponent` has [`copy`](http://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#copy()) and [`paste`](http://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#paste()) built in. And yes, if you use this functionality, it will be transferred via the system clipboard – MadProgrammer Jul 09 '14 at 09:10
  • do you have samples for JTextComponent copy paste as well ! – user3812293 Jul 09 '14 at 10:06
  • please take look into http://www.javalobby.org/java/forums/t19867.html. (it is also saying its dangerous ;)) – A Stranger Jul 09 '14 at 10:08
  • Start by taking a look at the linked java docs in the previous comment and [Text Component Features](http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html) and try something – MadProgrammer Jul 09 '14 at 10:16
  • one more question where to download java.awt.datatransfer – user3812293 Jul 09 '14 at 10:35
  • It's part of the JDK, if you want to the source, it's in the src.zip in the JDK directory – MadProgrammer Jul 09 '14 at 11:16
2

JComponent.setComponentPopupMenu(meu) also can be used.

A Stranger
  • 551
  • 2
  • 11