CTRL+Enter to go to next line

Hi
We have one chat application for which we have used TextArea for typing the messages. What we need is, while entering text in this TextArea, if we press CTRL+Enter cursor should go to next line(without posting the first line).
Any ideas for achieving this would be of great help. I am looking at achieving this by using keyboard events.
Sumukh

Here's a demo I just whipped up: Control+Enter will change the text color in the
current textarea, and I wired the action to a menu item as well.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
public class ExampleAction extends TextAction {
    private Random rnd = new Random();
    public ExampleAction() {
        super("Example Action");
    public void actionPerformed(ActionEvent e) {
        JTextComponent comp = getFocusedComponent();
        if (comp != null)
            comp.setForeground(new Color(rnd.nextInt(0x1000000)));
    public static void mapTo(JComponent comp, Action action, KeyStroke ks) {
        Object name = action.getValue(Action.NAME);
        comp.getInputMap().put(ks, name);
        comp.getActionMap().put(name, action);
    public static void main(String[] args) {
        Action action = new ExampleAction();
        Object name = action.getValue(Action.NAME);
        KeyStroke controlEnter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK);
        JTextArea area1 = new JTextArea(20,72);
        JTextArea area2 = new JTextArea(20,72);
        mapTo(area1, action, controlEnter);
        mapTo(area2, action, controlEnter);
        final JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
            new JScrollPane(area1), new JScrollPane(area2));
        sp.setPreferredSize(new Dimension(400,300));
        final JFrame f = new JFrame("ExampleAction");
        JMenuBar mb = new JMenuBar();
        f.setJMenuBar(mb);
        JMenu menu = new JMenu("Actions");
        menu.add(action);
        mb.add(menu);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(sp);
        f.pack();
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                f.setLocationRelativeTo(null);
                sp.setDividerLocation(0.5);
                f.setVisible(true);
}

Similar Messages

  • Pressing enter (hard return) moves next line to next pg/frame/col

    Hi,
    I read this was a glitch in German and Swedish CS5 Mac version.
    Options seem to be set correctly.
    Thanks

    Do you have the German or Swedish version? Have you updated to 7.0.3?
    This is actually also a fairly common problem on some Windows laptops where the BIOS maps the two enter keys together. Toggling NumLock switches the behavior between a column break and a paragraph break. I'm not sure if affects Macs without numberpads, but I think not.

  • Textlayout in SDK 4.5.1 do not support Ctrl+Enter

    Hi,
    We used spark textarea in Flex SDK 4.0 before and Enter, Shift+Enter, Ctrl+Enter can switch to new line. However, Ctrl+Enter can not switch to new line when we switch to Flex SDK 4.5.1.
    What should I do? Do I need to code it by myself?
    Looking forward someone to give me a guide.

    Try linking a Scroller into your app.

  • I'm having problem with text boxes.  Whenever i hit the enter button to start a new line or paragraph, the cursor doesn't drop down to the next line.  Instead i get this little red + sign in the box.

    I'm having problem with text boxes.  Whenever i hit the enter button to start a new line or paragraph, the cursor doesn't drop down to the next line.  Instead i get this little red + sign in the box.

    You are absolutely right.  Thought Enter meant Enter.  I was wrong.  Thank you for the help.
    Rod Rogers, Broker
    Accredited Land Consultant (ALC)
    Metcalf Land Company, Inc.
    Office: 864-585-0444
    Mobile: 864-316-0297
    Fax: 864-583-6000
    <http://www.metcalfland.com> www.metcalfland.com

  • When i type my email, the text would go on and on and overflows. I mean to say it doesn't autmatically hit the right hand side wall and change to next line! I have to manually press enter and then next line starts. Started happening suddenly.pls help.

    When i type my email, the text would go on and on and overflows. I mean to say it doesn't autmatically hit the right hand side wall and change to next line! I have to manually press enter and then next line starts. Started happening suddenly.pls help.

    Does it happen when you reply to an email? If so, it might be that there's content in the original email (like an image or something similar) that overflows the window content, therefore the Mail app, when you hit the border, follows the content below instead of going on a new line. You might wanna try that.
    Also: Please do not post the whole question in the question title.

  • I cannot get my text to advance to the next line when hitting enter???

    I cannot get my text to advance to the next line when hitting enter.
    Any suggestions??

    When I open Keyboard Shortcuts, the name field under Set: is highlighted in dark blue.  I cannot type a name in it.  The button NEW SET remains ungray.  When I click on the button no change happens to allow me to create new set.
    I also noticed that I am unable to scroll down in the InDesign document using scroll off mouse.
    So I have to click and drag to get around not using the up/down arrows when moving the illustrations.
    If I have to enter text I will use storybook.
    If I have to delete text I will use the InDesign document.
    Very limited with the functionality - I was better off using Adobe InDesign 2.0!
    Will need more time to investigate why the keyboard and mouse are not being recognized.  At this time I will have to use the work-arounds to meet deadlines and revisit later.

  • The Error Message 'Application descriptor file cannot be parsed' shows when compiling (Ctrl + Enter) Adobe AIR for Android applications on Flash Professional CS5.5

    The Error Message 'Application descriptor file cannot be parsed' shows when compiling (Ctrl + Enter) Adobe AIR for Android applications on Flash Professional CS5.5
    This is happening for most of the pupils and staff at our school and they are unable to complete their work.
    This also happens on a fresh copy of windows and CS5.5 without any updates and also with all latest updates.
    I have tried it on 32-bit and 64-bit CS5, Windows, Air and Java with the same error every time.
    There are a small minority of users where this works fine for them with no issue.
    I have tried re-setting user profiles.
    I have tried a local admin and domain admin account with the same issue
    I have noticed however that if the file is moved to the shared area it will compile. If it is on their documents area it will not compile. The users have full control in both locations. This is fine for staff but we are unable to give full control or modify access to the shared area for the pupil's
    I have been through the online support section and it directed me to phone Adobe Customer care who informed me that all support has been discontinued for CS5, CS5.5 and CS6 and they will only support creative cloud.
    Any ideas what to try next? There is no other information about this error and I cannot work out what is causing it.

    I have tried and  able to package an apk using your XML file.Could you please make sure your XML file starting from line 1 and coloumn 0.Any space will results in the error (Application Descriptor file cannot be parsed)
    -Pranali

  • Long text to be taken into next line

    Hi,
    I am passing a text in a FM in a BADI, but the text being long enters in the next line  which gives an error saying that 'Literals that take up more than one line are not allowed in OO context'.
    Can someone suggets some way of overcoming this other than storing the text in variables & concatenating it.
    Thanks.

    Hi
      I guess there is no other way apart from concatenating
    the text into a variable. If you dont want to declare a
    new variable for that you can use the same variable.
      move 'First Line' to l_text.
      concatenate l_text 'continuing' into l_text separated
    by space.
    Kind Regards
    Eswar

  • Text tool: Text doesn't goto the next line

    Hi,
    I ran into a problem where my text doesn't go to the next line when I press ENTER.  If I keep on typing, the text would overwrite itself.
    This is only happening in After Effects (it is fine in other apps...Email, Photoshop, etc.).  I know it is probably something I clicked but for the longest time, I couldn't figure it out.
    Any help appreciated.

    As Mylenium suggested, you may have a problem with line spacing. For example, you may have leading set to 0. One way to clear problematic settings is to reset the settings in the Character panel.

  • Flash Movie Works in Preview (Ctrl+enter) but not in Published

    Hi All-
    I hope somebody on here can help me out. I'm not sure what else to try. I have a flash project that I have been working on for a while, today its stopped functioning properly. To be clear. It still runs JUST FINE when I preview it (CTRL+ENTER), but when I publish the file and run  the SWF file, or  the HTML file the movie no longer functions properly. Specifically any ActionScript from the main timeline seems to no longer be functioning. ActionScript contained within movie clips continues to function properly, but nothing else.... .
    There is about 400 lines of code right now (variables, functions etc.) but if there is some where specific that I could provide I'm more then happy to. Thanks for your time and help.
    Regards,
    Nathan

    No, its in the same directory that it was before....
    I am not sure exactly where the problem is, but I am fairly sure that it has something to do with the flash player installed on my computer + the flash player installed by CS4....
    The SWF file runs properly when I host it on a site, but locally there is some type of conflict that causes all kinds of problems...
    If it helps:
    Windows 7 ultimate 64
    Flash CS4
    Flash Player 10.0.32.18
    If there is more info I can provide that can help you identify the problem please let me know, its rather frustrating.
    Cheers
    EDIT: For the record I have tried uninstalling the "player" and reinstalling but as of right now I continue to have problems.

  • Ctrl-Enter stopped working in the navigation toolbar in 3.6.13

    Ctrl-Enter has always been a standard feature in the navigation bar (URL / address bar). For example you type only "getfirefox" in the bar then press Ctrl-Enter and it autofills the http://www and the .com and submits the request, so you are taken to http://www.getfirefox.com without having to type anything other than "getfirefox" and Ctrl-Enter.
    This stopped working when I updated to 3.6.13. Also I cannot type a full URL and simply press Enter to submit it. The only way I can cause the browser to go to the URL I entered is to manually put the mouse cursor on the "right arrow" icon at the right end of the URL window and click that icon.
    As you can imagine, this is really annoying. I disabled all of my addons (I suspected Firebug or Web Developer of causing the problem) and the problem still persisted anyway. I reinstalled Firefox 3.6.13 and the problem is still the same. I wonder if it has anything to do with Firefox 4 beta being installed on my system. But I don't try to use them at the same time.

    I knew AVG Safe Search couldn't be the problem because I had uninstalled it! Guess what. It was uninstalled, all right, but the add-on to Firefox was still there, disabled. That uninstall was grayed out.
    I re-enabled it and disabled it, this time it said it would be uninstalled the next time I restarted Firefox. So I did that. Nothing changed. However, this time I noticed that just above the restart message was a place to click restart. That restart worked!
    Some people just know how to write obtuse software messages.

  • How to get text in Next line of Label

    Hi,
    I am trying to write a code where when I press Enter the text in the text box appear on next line of label. However every new text is getting printed on the same line..
    Here is my code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ChatBox extends Applet implements ActionListener
      TextField firstNum, secondNum, resultNum;
      Label label1;
      String str1 = "Start Chatting";
      public ChatBox()
      //setLayout(new GridLayout(3, 2, 10, 15));
      setBackground(Color.cyan);  
      String message;
      message = "Start Typing and see the magic";
      setLayout(new GridLayout(2,1,10,120)); //, 10, 15));
      setBackground(Color.cyan);  
      firstNum = new TextField(5);
      firstNum.addActionListener(this); 
      label1 = new Label(firstNum.getText());
      add(label1);
      add(firstNum);
      public void actionPerformed(ActionEvent e)
      String newline = System.getProperty("line.separator");
      //String message = "Start Typing and see the magic";
      str1 = str1+ newline + firstNum.getText();
      firstNum.setText("");
      //message = message + str1;
      label1.setText( str1 );

    Is it not possible?
    Kindly guide with an alternative way to do this.

  • Type won't go to the next line. Please help!

    Everytime I create a text box in Indesign and start typing; instead of going to the next line, the text disappears and the little red box shows up. The text box is big enough, the text just won't go to the next line. Can someone please help me?

    And presumably when you say "won't go to the next line" you mean it doesn't wrap onto the next line on its own as you type, and not that you are pressing enter and it suddenly disappears? If it's failure to wrap and the frame is deep enough for another line, then it's either No Break, or you have hyphenation disabled and are typing non-breaking spaces (but that takes more effort to do than accidentally setting No Break as the default so is less likely).
    If the frame is not deep enough for an additional line, it's what Nini said, but if it's really that you are pressing the Enter key and it goes into overset it means you are either pressing the Enter key on the number pad, which inserts a column break by default, or you are one of those unfortunate souls (mostly PC laptop users) whose keyboard maps both enter keys together. Toggling numlock on such machines usually also toggles between paragraph and column breaks, but it's annoying and you might want to edit the shorcuts if this affects you.

  • Getting Buffered Reader to read next line and update.

    Hello.
    I have been trying to get this program to read the next line in a txt file correctly. This is a GUI program
    where clicking the button is supposed to bring up the next bit of information for the user to see.
    I can get the first line of information to come out correctly, but I am unable to get it to read the next line when I click the next button.
    Here is a snippet of my coding...
    private JFileChooser fileChoose;
    private File openedFile;
    private int recordNumber = 0;
    FileReader inFile;
    String sMaker = new String (  );
    else if ( ae.getActionCommand (  ) == "Next Record" )
         if ( openedFile.exists (  ) )
              nextRecord (  );
         else
         JOptionPane.showMessageDialog ( null, "No Files Opened", "No Files Found", JOptionPane.ERROR_MESSAGE );
    public void nextRecord (  )
         recordNumber ++;  // Increment record number
         fileNumber.setText ( sMaker.valueOf ( recordNumber ) );  // Prints to JTextField for user to see
         BufferedReader inText;
         String lineRead;  // Holds line read in
         String [] organizedInfo;  // Array to hold info after being split
         try
              inFile = new FileReader ( openedFile );
              inText = new BufferedReader ( inFile );
              lineRead = inText.readLine (  );
              organizedInfo = ( lineRead.split ( "," ) );//.trim (  );
              for ( int i = 0; i < organizedInfo.length; i ++ )
                   organizedInfo[i] = organizedInfo.trim ( );
    name.setText ( organizedInfo[0] );
    city.setText ( organizedInfo[1] );
    state.setText ( organizedInfo[2] );
    catch ( FileNotFoundException fnfe )
    JOptionPane.showMessageDialog ( null, "Selected File was Not Found", "File Not Found", JOptionPane.ERROR_MESSAGE );
    catch ( IOException ioe )
    JOptionPane.showMessageDialog ( null, "IO Error. Please Try Again.", "IO Error", JOptionPane.ERROR_MESSAGE );
    employee.txt
    William Wallace,Richmond,VA
    Samuel Gompers , San Francisco , California
    Andy Smith,Rochester,NY
    Sandy Beach,Pittsford,NY
    Slim T. None,San Francisco,CA
    George Jones, Washington , D.C.
    Marvin Martin, Boston , Massachusetts
    I. M. Last , Deadmans Gulch, Arizona
    Everytime I click the next button, it should go through the list in employee.txt until i reach the end. But it just stops at William Wallace.
    I know that this can be recoded to make it more efficient, but before that, I still need to figure out how to get the line read to update to next line.
    Thank you in advance.

    Your program works perfectly correctly!
    Each time you click the button it reads the first line and displays it. Why? Because you create a new reader everytime you enter the nextRecord method and the reader reads the first line. Each new reader has no idea where the last reader was upto in your file. It has to start at the beginning.
    <cue response>How do I fix it?

  • Continuing a string in the next line

    How can a string be continued in the next line ... in the below function call for popup_title i have to give 'Enter Sold-to party's Postal code and Region'
    CALL FUNCTION 'POPUP_GET_VALUES'
      EXPORTING
      NO_VALUE_CHECK        = ' '
        POPUP_TITLE   =  'Enter Postal code and Region'
       START_COLUMN          = '5'
       START_ROW             = '5'
    IMPORTING
      RETURNCODE            =
      TABLES
        FIELDS                = IVALS
    EXCEPTIONS
      ERROR_IN_FIELDS       = 1
      OTHERS                = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    I appreciate your response

    Please try.....
    <b>data: title_string type string.
    title_string  = 'Enter Sold-to party<b>''</b>s Postal code and Region'.</b>
    call function 'POPUP_GET_VALUES'
    exporting
    * NO_VALUE_CHECK = ' '
    <b>popup_title = title_string</b>
    start_column = '5'
    start_row = '5'
    * IMPORTING
    * RETURNCODE =
    tables
    fields = ivals
    * EXCEPTIONS
    * ERROR_IN_FIELDS = 1
    * OTHERS = 2
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    Regards,
    Rich Heilman

Maybe you are looking for

  • ALV to Excel Missing field content

    Hi Experts, I have a problem during dowloading process of ALV grid to Excel. For some reasons the last row is not completely filled with all field contents. I tried 2 things one is working fine and one is not working fine. 1) List --> Export ---> Spr

  • How to open pdf file with command?

    I had trouble to open local pdf file with command by WebBrowser control in IE.(The Acrobat version is 6.0 or 7.0 in my PC) The pdf command can be getted in this: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf I open a loc

  • Can somebody explain relation between BAM and TrackingHost

    In My application I have used BAM API to track some business data. Is it mandatory to have at lease one tracking host is running to move data between BizTalk Message box database to BAM primary import database? Thanks Ammu.

  • IPhone 4  cannot update or restore after updating ios7

    Help!  Iphone 4 stuck on recovery mode and cannot get out after updating ios 7. 1. I already tried this as well, no luck: http://support.apple.com/kb/ht1808 2. Got caption on Iphone after trying to restore: The iPhone could not be restored. An unknow

  • Switching from numpad to qwerty

    hey guys, i'm wondering if there's any way to get the iphone to switch to a full qwerty (or at least show me symbols) when it's showing the numpad. the only input choices i seem to get is 0-9, #, *, and "pause (,)". thanks! kyle