Paste with button

Hi.
I must simulate paste action with a jbutton.
When i click on jbutton i have to paste all in a component like jtextarea.
Can help me with an example?

TextComponents have ActionMaps that have actions for cut/copy/paste. You just need to get the map for the component and get the action for the process you want:
public class TextActionTest extends JFrame {
    private JTextComponent textarea;
    public TextActionTest() {
        buildGUI();
    private void buildGUI() {
        JPanel mainPanel = (JPanel) getContentPane();
        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(buildCenterPanel(), BorderLayout.CENTER);
        mainPanel.add(buildButtonPanel(), BorderLayout.SOUTH);
        pack();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
    private JPanel buildCenterPanel(){
        JPanel retPanel = new JPanel(new GridLayout(1,0,5,5));
        textarea = new JTextArea(4,25);
        Action[] actions = textarea.getActions();
         System.out.println(actions);
        JScrollPane jsp = new JScrollPane(textarea);
        retPanel.add( jsp);
        return retPanel;
    private JPanel buildButtonPanel(){
        JPanel retPanel = new JPanel(new GridLayout(0,3,5,5));
        JButton copyButton = new JButton(textarea.getActionMap().get("copy-to-clipboard"));
        copyButton.setText("Copy");
        JButton cutButton = new JButton(textarea.getActionMap().get("cut-to-clipboard"));
        cutButton.setText("Cut");
        JButton pasteButton = new JButton(textarea.getActionMap().get("paste-from-clipboard"));
        pasteButton.setText("Paste");
        retPanel.add(copyButton);
        retPanel.add(cutButton);
        retPanel.add(pasteButton);
        return retPanel;
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            public void run() {
                TextActionTest textActionTest = new TextActionTest();
                textActionTest.setVisible(true);
        SwingUtilities.invokeLater(runnable);
}Cheers
DB

Similar Messages

  • How to cut and paste with MacBook Air

    How do I cut and paste with MacBook Air?

    Copying, Cutting, and Pasting in OS X
    You can easily copy, cut, or paste pictures, text, and other items easily using the built-in shortcuts and menus in OS X.
    Copying text
    To copy text, you can either secondary-click the text or use OS X’s built-in keyboard shortcut.
    To copy using secondary-click, first secondary-click the text. Then, select the Copy button from the pop-up menu.
    To copy using the keyboard shortcut, select the text. Then, press both the C and Command (⌘) keys at the same time.
    Cutting text
    To cut text, you can either secondary-click the text or use OS X’s built-in keyboard shortcut.
    To cut using secondary-click, first secondary-click the text. Then, select the Cut button from the pop-up menu.
    To cut using the keyboard shortcut, select the text. Then, press both the X and Command (⌘) keys at the same time.
    Pasting text
    To paste text, you can either secondary-click the text or use OS X’s built-in keyboard shortcut.
    To paste using secondary-click, first secondary-click the text. Then, select the Paste button from the pop-up menu.
    To paste using the keyboard shortcut, select the text. Then, press both the V and Command (⌘) keys at the same time.
    Austin

  • How Can I Get Back the Options to Paste with Formatting?

    I am using Dreamweaver CS5 on a Windows 7, 64-bit machine.  It's been up and stable for months and months.
    I don't recall installing anything before this happened or doing anything strange, but...
    ... recently Paste Special or Paste has stopped allowing me to past with either "Text with structure plus basic formatting (bold, italic)" or "Text with structure plus full formatting (bold, italic, sytles)
    Those last two radio buttons on the Paste Special panel are grayed out.
    This afternoon I re-installed DW CS5 from the installation discs and ran the updater (I did NOT first delete DW.)  Reinstalling did NOT repair the problem.

    Here is what is going on..
    the above image is the default dreamweaver c&p
    the above image is the area trying to paste.. which includes an entire row of html within a table and includes an image. so i try to copy and paste.. the following is the end result.
    and finally here is the paste special options i am given.

  • My network symbol keeps working on my home page even when I'm not doing anything, I know there has been problems in the past with this so has it come back, help it's killing my battery!

    My network symbol keeps working on my home page even when I'm not doing anything, I know there has been problems in the past with this so has it come back, help it's killing my battery!

    Close all open apps by double-tapping the home button, then swiping up and off the screen with the app window (not the smaller icon).
    Reset your device: hold down the home button along with the sleep/wake button until the screen goes black and you see the Apple, then let go. (No data loss)

  • I can't seem to copy or cut and paste with firefox anymore

    I can highlight but I can't cut or paste words or phrases on firefox anymore. I can on explorer but not firefox
    == This happened ==
    Every time Firefox opened
    == its been a while not sure what setting got changed

    ~~red:''<u>'''Please list your Extensions & Themes when posting a question'''</u>''~~
    When posting future questions, please post the information in the "Troubleshooting Information" section. See: [[Using the Troubleshooting Information page]]
    ~~red:''<u>'''Can not copy/cut and paste'''</u>''~~
    The two most commonly reported causes of not being able to right-click, Copy and Paste are AVG Safe Search and Yahoo Toolbar. ~~red:'''Disable them and test'''~~ ( Tools > Add-ons > Extensions , locate and click on each of the add-ons, click Disable, when both are disabled, click Restart Firefox in the Extensions window.)
    If the right-click context menu allows copy/cut and paste with the two add-ons disabled, then one or both of them is causing the issue. Re-enable the extensions one-at-a-time, restart Firefox and test. When the problem returns, you will know which is the culprit.
    See:
    http://support.mozilla.com/en-US/kb/Customizing+Firefox+with+add-ons
    http://support.mozilla.com/en-US/kb/Troubleshooting+extensions+and+themes
    http://support.mozilla.com/en-US/kb/Uninstalling+add-ons
    http://support.mozilla.com/en-US/kb/Troubleshooting+plugins
    ~~red:<u>'''''Other Issues'''''~~: to correct security/stability issues</u>
    <u>'''Update Java'''</u>: your ver. 1.6.0.17; current ver. 1.6.0.20 (<u>important security update 04-15-2010</u>)
    ''(Windows users: Do the manual update; very easy.)''
    See: '''[http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates Updating Java]'''
    Do the update with Firefox closed.

  • I can't sync like in past with my iPhone 5 to MacBook... color ball spins and it want's to go to App Store? Never connects

    I can't sync like in past with my iPhone 5 to MacBook... color ball spins and it want's to go to App Store? Never connects
    In past, when I connected USB cable it tarted syncing... now it shows grey IPhone so it knows it's connected, but doesn't let me select it. I keeps going to the store and never "responds" so I have to Force Quit each time.
    I tried using Bluetooth and it almost worked but then said the iPhone didn't support my MacBook. ?!?
    I figure everything is so automated (old term from an old guy) that I've missed something. I miss the Apple 2e's and c's sometimes. I've almost wanted to ask verbally my phone to do it but am holding that adventure until I hear from someone. [ I asked my iPad one time for help and it told me it was busy and ask later.  "Seri-ously:-)  ]
    Help!

    Hello lenmin,
    Thanks for using Apple Support Communities.
    To help resolve this issue where you're repeatedly prompted to authorize with your Apple ID in iTunes when syncing, please follow the directions in the article below.
    iTunes: Missing folder or incorrect permissions may prevent authorization - Apple Support
    Have a great weekend,
    Alex H.

  • Having trouble with buttons in motion menus

    I'm having some problems with buttons in motion menus:
    - I've created a motion menu where some text (button names) fade in.
    - I set a loop point after the text has faded in completely.
    - I set the end condition to "loop"
    (there is some animation after the text fades in that I would like to loop)
    - I draw out 5 buttons and assign different overlay colors to each of the button states.
    The problem is that each time the motion menu jumps back to its loop point.. the menu seems to stutter - the overlay color on the currently selected button turns off for a second and the button is momentarily disabled (can't be selected). This problem only shows up on the actual dvd build. The buttons work smoothly when tested in the simulator.
    I can avoid this problem by losing the animation and just setting the end condition to "still".. but I was wondering if anyone knows if there is something I might have missed or could try as a workaround.
    17" powerbook g4   Mac OS X (10.4.5)  

    This problem only shows up on the actual dvd build. The buttons work smoothly when tested in the simulator.
    It could be how the DVD is reading the DVD (sort of the nature of DVD, everything is not exactly the same), because buttons will not show until the loop point and there may be a slight pause from end of animation in the menu to the loop point. And the overlay will turn off briefly when it hits the end.
    Visually what you can do is make the animation in a manner so that at the loop point the buttons are part of the background itself and make sure your loop point is at that point (or slightly after) so it looks like the button is there.
    For the most part the setting of still may work okay (really a creative call), sometimes listening to the same music/seeing samee animation may be too much (of course it depends on project) and you can jump to the loop point on the menu on subsequent calls

  • How to make a scroll Bar with buttons

    Hi all,
    I am using Flash cs6 on an iMAC running 10.7.2
    I would like to know if anyone could please point me to a tutorial, showing "how to create a scroll bar with buttons". I am having a heck of a time finding a tutorial.
    Many thanks in advance.
    regards,
    DH

    http://learnola.com/2008/10/27/flash-tutorial-create-a-custom-scrollbar-with-actionscript/

  • How to make a navigation bar with buttons that stay highlighted

    I have Dreamweaver MX 2004. I know how to make a simple nav
    bar, but how do you make it so it's like the Apple website, with
    buttons that stay highlighted on the appropriate page?

    "[email protected]" <[email protected]>
    wrote in message
    news:gd04sb$5mc$[email protected]..
    >I have Dreamweaver MX 2004. I know how to make a simple
    nav bar, but how
    >do you make it so it's like the Apple website, with
    buttons that stay
    >highlighted on the appropriate page?
    http://divahtml.com/products/divaGPS/current_menu_location.php
    Thierry
    http://www.TJKDesign.com/go/?0
    | Articles and Tutorials
    http://divahtml.com/products/scripts_dreamweaver_extensions.php
    | Extensions
    that keep your markup clean
    http://www.fourlevel.com/ |
    CSS Menus, Gallery, Tab Panels, etc

  • Help with buttons :S

    hi all,
    i'm new to flash but i have an idea whats going on with webpages. I need some help with buttons! i have a website and its has a stage and 9 different flv's (screens). I've been trying to read online and i can't find out how to navigate to different screens, example below
    home          |            |
    about us     |  stage   |
    contact       |            |
    you click one one button it updates the stage. also i'm using actionscript 2.0.
    thanks for any help ahead of time
    Thank you,

    Is it a wi-fi or cellular connection that isn't working?  If its wi-fi and other people/computers/phones can connect check your settings.  If its cellular, are other people's phones (on the same carrier) working in the same location? If other people can't connect then it is likely a network problem.  If others can you may need to reset/restore you iPhone.

  • Interactive Prototype - How do you simulate light boxes with buttons? (CS4)

    I am in the process of mocking up an interactive prototype of the homepage of a web application.  On this homepage, there are various links(text with slices) and fields that when clicked on will trigger a dialog to appear over the top of the page similar to a "light box" effect seen on many other websites/applications.
    The workflow I am trying to simulate is as follows:
    User clicks the text link (state 1)
    Dialog appears on top of current page (state 2)
    User fills in necessary fields then clicks save button (state 2)
    Dialog disappears and returns user to base state (state 1)
    The base state of the page is in state 1.  I placed the images/content for the light box in state 2 and then added an onclick image swap behavior to have the link in state 1 trigger the light box (also a slice) to appear in state two.  That all worked fine until I added a save button symbol from the common library to the lightbox dialog in state 2.  When I did that, Fireworks automatically brought be back to state 1 and the button appears on both/all states no matter what I try to do.  Also, my attempts to add an onclick behavior to the save button to bring me back to state 1 haven't worked either.
    So my questions are:
    How do I get that button only to appear on state 2?
    The "hotspot" for that button or any slice/hotspot in any state appears active for all states but are only valid for when that certain dialog appears.  Is there a way to manipulate button/slice hotspots across states so they are only active in the correct states?
    How do I get the Save button to bring me back to the base state?
    Mocking up a lightbox type dialog seems like it would be a pretty common thing to do so I am hoping this is just a simple mistake I am making... any help would be greatly appreciated!
    Here are some images to help illustrate what I am trying to do: 
    Desired:
    Here is what Fireworks is doing:
    State 1 w/link behavior
    State 1 with button behavior (this appears on state 1 no matter where I add the button but I want it only to appear in state 2)
    State 2
    And here is the actual fireworks png proof of concept:

    Hi Linda,
    Thanks for the suggestion, however, that doesn't appear to be working.  I've uploaded the file that I am using as my proof of concept.  You can download it via the link below.  I changed the button so it's only a graphic with a slice over it but there are still two issues.  When the save button is clicked the state does not change back to state 1.  The second problem is that even in state 1, the active area for the save button slice in state 2 is still active even though the button is not there. Any thoughts?
    https://docs.google.com/leaf?id=0B0Fc5EuxtTzPMzY0NTA4ZGQtZjc1Yi00Njk3LThlOTUtYmFlZWQyNzQ5N GVj&sort=name&layout=list&num=50
    Thanks,
    Greg

  • Can't drag and drop nor copy  and past with iMac with OS 10.8.1.

    Can't drag and drop nor copy and past with iMac with OS 10.8.1.  Not with iTunes, MS Word, nor Pages.  No where.  Reboot or relogging in helps for about an hour.  Hard reset worked for a short time. Per Apple support, most likely will reinstall the operation system.  Just wondered if anybody else has run into this.  Did a disk scan, and that was fine.  And did rebooting, holding down CMD+OPT+R, and P..  Deleted all the start up programs.  Checked the internet, no solutions there.  So it all appears to be OS redo time. 

    Do you subscribe to MLB.tv, and if so, did you install the NextDef plug in? If so, read this…
    https://discussions.apple.com/message/19185556#19185556
    I removed the NextDef plug in over 24 hours ago, restarted and haven't had a single issue with drag and drop or cut and paste since.

  • Draging a box with button attached on stage excuting button problem

    Hi,
    I have a box on the stage, which is a movie clip. I opened
    this movie clip and placed a button on it. I want to be able to
    drag the box on the stage and the button to move with it. Also I
    want to be able to press the button , which take me to frame 2. I
    have done all of this but the button will not activate. The code I
    have written is:
    box_mc.onPress =function(){
    startDrag(this);}
    box_mc.onRelease=function(){
    stopDrag()};
    stop();
    I opened the movie box (where i placed the button) I wrote
    the following code:
    gotoframe2_btn.onRelease=function(){
    gotoAndStop(2)};
    However, I can drag the map (with button attached) but cannot
    press the button, to perform the action, to bring me to Frame 2. I
    have created a 2nd Frame in the Timeline on the main stage and also
    on the Timeline when i open the movie of the box.
    Hope you can help
    Thanks
    Paul

    Oh, sorry about that, I didn't see the code you posted in the
    previous topic I made
    but thanks a lot i got it working!

  • While in email today, the computer began flashing. I had to turn off with button. When I turned it back on, I got the apple icon and the moving loading wheel. It would turn for about 60 seconds and then stop. I turned off again. I now have a black screen.

    while in email today, the computer began flashing. I had to turn off with button. When I turned it back on, I got the apple icon and the moving loading wheel. It would turn for about 60 seconds and then stop. I turned off again. I now have a black screen.

    Hi wiesenruth,
    If you are having issues starting up or booting your computer, you may find the following articles helpful:
    Troubleshooting: My computer won't turn on
    http://support.apple.com/kb/TS1367
    Mac OS X: Gray screen appears during startup
    http://support.apple.com/kb/ts2570
    Regards,
    - Brenden

  • Putting frame with buttons into a thread

    please help!!!
    i've got a thread:
    package aJile;
    import java.io.*;
    import java.net.*;
    public class SocketHandler extends Thread
      private Socket socket;               // Socket used for messages 
      private int socketNr;
      private byte[] inbuf;
      private InputStream in;
      private OutputStream out;
      public SocketHandler(Socket socket)
        this.socket = socket; 
      public void send(String str) throws IOException {
           out.write(str.getBytes(), 0, str.length());
           out.flush();              
      public String receive() throws IOException {
           int numBytes = in.read(inbuf);
          String str = new String(inbuf, 0, numBytes);
          return str;
      public String switchOn() throws IOException {
           send("1");
           String state = receive();
           return state;
      public void run()
        try {
          // set up the input and output streams
          in  = socket.getInputStream();
          out = socket.getOutputStream();
          inbuf = new byte[128];
          receive();
         // System.out.println(switchOn());     
          in.close();
          out.close();
          socket.close();
          System.out.println("closing");
        catch (Exception e)
          System.out.println("Caught exception "+ e);
    }and i want to add a frame with buttons to this thread. that everytime tread starts, this frame would appear. and that methods of the thread would be called with a button press. How to join them?
    here is a frame:
    package buttons;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame3 extends JFrame implements ActionListener
         JPanel pane = new JPanel(); 
         Icon lightIcon = new ImageIcon("light.gif");
         Icon darkIcon = new ImageIcon("dark.gif");
         JButton pressme = new JButton("Press Me");
         JButton ironButton = new JButton("Iron",lightIcon);
         JButton lampButton = new JButton("Lamp",lightIcon);
         JButton ovenButton = new JButton("Oven",lightIcon);
         public Frame3()  
              super("Event Handler Demo"); setBounds(100,100,300,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Container con = this.getContentPane(); // inherit main frame
              con.add(pane);
              pressme.setMnemonic('P');
              pressme.addActionListener(this);   // register button listener
              ironButton.addActionListener(this);
              lampButton.addActionListener(this);
              ovenButton.addActionListener(this);
              pane.add(ironButton);
              pane.add(lampButton);
              pane.add(ovenButton);
              pane.add(pressme);
      public void actionPerformed(ActionEvent event)
        Object source = event.getSource();
        if (source == pressme){     
          JOptionPane.showMessageDialog(null,"Hello!","Message Dialog",
          JOptionPane.PLAIN_MESSAGE);
        if (source == ironButton){
             if (ironButton.getIcon() == lightIcon){
                  ironButton.setIcon(darkIcon);               
             else ironButton.setIcon(lightIcon);
        if (source == lampButton){
             if (lampButton.getIcon() == lightIcon)
                  lampButton.setIcon(darkIcon);
             else lampButton.setIcon(lightIcon);
        if (source == ovenButton){
             if (ovenButton.getIcon() == lightIcon)
                  ovenButton.setIcon(darkIcon);
             else ovenButton.setIcon(lightIcon);
      public static void main(String[] args){
           Frame3 app = new Frame3();
           app.setVisible(true);
    }thank you

    could you tell me how to avoid exceptions?
    what i want to to is to call a method wich simply sends a string and gets a string back.
    public String switchOn() throws IOException {
           send("1");
           String state = receive();
           return state;
      }but when i call this method in actionPerformed() i get exceptios and my socket closes. It sends the string though, but after this program crashes. is there anything special to do if i want to use this Frame3 in order to communicate with a client by pressing buttons?

Maybe you are looking for