Clipboard Problem in JTextArea

I am writing a text editor in swing and when i used the system clipboard for my JTextArea, the pop-up menu of cut,copy,paste delete and select all that normally appears in TextArea didn't appear. What could be the possible solution? Please note that when i use TextArea instead of JTextArea, my menubar goes behind the text area, and thus creates problem.
Could anyone give me a hand please? I would request you to be elaborative and give me some lines of codes if you can find the solution.
Thanks

JTextArea by default does not show the drop down menu. You have to trap the right click on the JTextArea and show the JPopupMenu. Also, to enable cut, copy, paste etc.. you have to call the JTextArea.cut(),copy(),paste() and the selectAll() methods on the action event occuring during the menu item selection of your popup menu.
Cheers

Similar Messages

  • Problem using JTextArea

    Hi!
         I' ve a problem using JTextArea. I'm trying to discuss in a brief.....
    I've created an application that is used as a front end for a SQL database application.
    There is a text area (JTextArea). Clicking on a button, what I enter in the text area would be saved into the database. As well as, the text area would be used to display the data (a few line) that the database already contains. That is to say, that a user can edit new text to store into the database and modify older text that is already stored in the database.
    A line the text area would contain could be as long
    as this line.
    Or, a line may be long like this.
    < There may be a gap / empty line >
         A line may be start & end in these positions.
    figure: a text area (JTextArea)
    Suppose that someone used this text area to edit a few lines as the figure displays.
    Now, the next time when he will return here after doing some other tasks with this application or, after reopening the application; the text area should display the entire text the database contains in the format it was edited (See the figure).
    But, I failed to do all the things I sated above! (Except the job with database)
    I don't have any problem in database connectivity or getting the text (String) a database contains.
    Would you please send me a code that explains how to achieve the things I need?
    Please........

    Hellow again !
    Your suggestion to use the methd trim() did not help to the problem I mentioned. But you would be glad to know that the method solve the another problem I had.
    But !...but I' m still in the same condition.
    Well, Canad! I think the another one you said the 'padding' is unable to work successfully as the text area and hereafter the database would contain multiple lines and not only one line. Because, after editing one line if I fill the rest of the space ( space to store string / text in a column of the database ) then where the other lines that would be entered into the text area would be stored ?! (See your suggestion 'padding')
    I can not find out anything & I'm getting tired. Would you do something at my request ?
    Please...Please...Please... send me a code that helps to achieve what the actually I need and ofcourse, explains clearly.

  • Problem with JTextArea or is it my code, Help!!!

    Hi,
    I am going crazy. I am sending a message to a JTextArea and I get some very wierd things happening? I really need help because this is driving me crazy. Please see the following code to see my annotations for the problems. Has anyone else experienced problems with this component?
    Thanks,
    Steve
    // THIS IS THE CLASS THAT HANDLES ALL OF THE WORK
    public class UpdateDataFields implements ActionListener {     // 400
         JTextArea msg;
         JPanel frameForCardPane;
         CardLayout cardPane;
         TestQuestionPanel fromRadio;
         public UpdateDataFields( JTextArea msgout ) {     // 100
              msg = msgout;
          }       // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
              String reset = "Test of reset.";
              try{
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        Interface.changeCards();
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
              try{
                   if (command.equals("ButtonA")){     // 300
    // WHEN I CALL BOTH OF THE FOLLOWING METHODS THE DISPLAY WORKS
    // BUT THE CHANGECARDS METHOD DOES NOT WORK.  WHEN I COMMENT OUT
    // THE CALL TO THE DISPLAYMESSAGE METHOD THEN THE CHANGECARDS WORKS
    // FINE.  PLEASE THE INTERFACE CLASS NEXT.
                        Interface.changeCards();
                        Interface.displayMessage("test of xyz");
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
         }     // 200
    }     // 400
    // END OF UPDATEDATAFIELS  END END END
    public class Interface extends JFrame {     // 300
         static JPanel frameForCardPane;
         static CardLayout cardPane;
         static JTextArea msgout;
         TestQuestionPanel radio;
         Interface () {     // 100
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new CardLayout();
              frameForCardPane = new JPanel();     // for CardLayout
              frameForCardPane.setLayout(cardPane);     // set the layout to cardPane = CardLayout
              TestQuestionPanel cardOne = new TestQuestionPanel("ABC", "DEF", msgout, radio);
              TestQuestionPanel cardTwo = new TestQuestionPanel("GHI", "JKL", msgout, radio);
              frameForCardPane.add(cardOne, "first");
              frameForCardPane.add(cardTwo, "second");
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              ButtonPanel commandButtons = new ButtonPanel(msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));             pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30));
              pane.add(frameForCardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
         }     // 100
    // HERE ARE THE METHODS THAT SHOULD HANDLE THE UPDATING
         static void changeCards() {     // 200
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
         }     // 200
         static void displayMessage(String test) {     // 200
                   String reset = "Test of reset.";
                   String passMessage = test;
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
                   msgout.append("\n"+ test);
         }     // 200
    }     // 300

    Hi,
    I instantiate it in this class. Does that change your opinion or the advice you gave me? Please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    }

  • Selection problem in JTextArea

    hi all
    i have a TextArea in which i have some coded charecters in a group of ten charactes i treet these ten characters as a single character ,so when i delete or insert these charactes all these charactes r deleted and no other character r inserted in between , i do it with the caretListener,
    But the problem which i face is on the selection i want to select these characters as when we select some part of the URL then it is selected completely.
    help in the prob.

    this might work
    paste some text into the textArea (ensure it contains a sequence "12345")
    click anywhere in area of 12345
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    class Testing extends JFrame
      String specialChars = "12345";
      boolean settingCaret = false;
      public Testing()
        setSize(200,200);
        setLocation(300,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        final JTextArea ta = new JTextArea(10,10);
        JScrollPane sp = new JScrollPane(ta);
        sp.setPreferredSize(new Dimension(175,150));
        JPanel jp = new JPanel();
        jp.add(sp);
        getContentPane().add(jp);
        pack();
        ta.addCaretListener(new CaretListener(){
          public void caretUpdate(CaretEvent ce){
            if(settingCaret == false)
              int startPos = ta.getText().indexOf(specialChars);
              if(startPos > -1)
                if(ta.getCaretPosition() >= startPos && ta.getCaretPosition() <= startPos+specialChars.length())
                  settingCaret = true;
                  ta.setSelectionStart(startPos);
                  ta.setSelectionEnd(startPos+specialChars.length());
                settingCaret = false;
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Acrobat Reader 9.5.0 has Clipboard problems

    Repro:
    Launch Microsoft Word 2010.
    Launch Adobe Reader one any Web document.
    Switch to Microsoft Word and Copy some text onto the clipboard.
    And quickly switch back to Adobe Reader and copy some text from there.
        "There was an error while copying to the Clipboard.  An internal error occurred."
    > KernelBase.dll!_RaiseException@16()  + 0x58 bytes
      msvcr80.dll!72ae8e89() 
      [Frames below may be incorrect and/or missing, no symbols loaded for msvcr80.dll]
      AcroRd32.dll!024c3371() 
      AcroRd32.dll!024c38e4() 
      AcroRd32.dll!01fac1e2() 
      AcroRd32.dll!01facaa2() 
      AcroRd32.dll!02093802() 
      AcroRd32.dll!020938d9() 
      AcroRd32.dll!01fac265() 
      AcroRd32.dll!02066b37() 
      AcroRd32.dll!0216cfc6() 
      AcroRd32.dll!020910fd() 
      AcroRd32.dll!02092f1d() 
      AcroRd32.dll!01e1d007() 
      AcroRd32.dll!02042d80() 
      AcroRd32.dll!0204367b() 
      AcroRd32.dll!01fa806e() 
      AcroRd32.dll!0216f585() 
      AcroRd32.dll!0206cd78() 
      AcroRd32.dll!01f99a4e() 
      AcroRd32.dll!01f99b47() 
      AcroRd32.dll!01f05ba6() 
      AcroRd32.dll!01f05930() 
      AcroRd32.dll!01f058a7() 
      AcroRd32.dll!01f05396() 
      AcroRd32.dll!01f052ab() 
      AcroRd32.dll!01e13976() 
      kernel32.dll!74f1140f() 
      0051fe58()
      00000003()
    Clearly Acrobat Reader has a problem.  If you point me at the symbols for AcroRd32 I'll help debug it for you since I can repro it easily.

    Here are few solutions:
    1. You can configure firefox to open pdf in external application like acroread. This way plugin problem is bypassed. - I use it this way. It looks to be faster this way.
    2. "C:\nppdf32Log\debuglog.txt" is created every time in directory from where you executed firefox/opera/other browser and opened any pdf file in browser. So this is not only home directory. You can fix this problem by yourself by hex editing nppdf.so file and replacing C:\nppdf32Log\debuglog.txt path in this file with /dev/null path. See my post here for detailed instructions: http://forums.adobe.com/thread/1253800

  • Problem with JTextArea

    Hi all,
    I am having a class which extends JTextArea. I press backspace and I check for some condition in KeyReleased event. If the condition is true I am setting the JTextArea with the old text(retainText). What happens here is that first the backspace entered by me is reflecting on the screen and then only the new text (retainText) is set. This causes a flickering on the text area. My requirement is that this should not happen.
    Is there any way to avoid this .
    or else Is there any way to cancel this event ( say i enter backspace and if the condition becomes true in the KeyReleased event, I should stop this event. Can any body please help me ASAP. Thanks!!!
    I ve attached the code also
    package com.bankofny.iic.client.component;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    import com.bankofny.iic.client.instruction.viewer.TradeDetailForm;
    import com.bankofny.iic.common.util.StringFormatter;
    public class IicTextAreaSwift extends JTextArea implements FocusListener, KeyListener
        // IicTextAreaSwift Method
         private int DescCharWidth = 0;
        private int DescCharHeight =0;
         private String retainText; //retain always the latest text
         private int KeyCode;
         private String KeyText="";
        public IicTextAreaSwift(int _rows, int _columns, boolean scrollPane)
            super(_rows, _columns + 1);
            setDisabledTextColor(Color.gray);
                rows            = _rows;
            columns         = _columns;
            setRows(_rows);
            maxTextAllowed  = _rows * _columns;
            setBorder(new BevelBorder(BevelBorder.LOWERED));
            setLineWrap(true);
            setWrapStyleWord(true);
            Font fixedFont = new Font("Courier", Font.PLAIN, 12);
            setFont(fixedFont);
            FontMetrics fm = getFontMetrics(fixedFont);
            DescCharWidth = fm.charWidth('W') * (_columns + 1);
          //  DescCharHeight = fm.getHeight() * 4 ;
               DescCharHeight =  DEFAULT_LABEL_HEIGHT * 3;
            setPreferredSize(new Dimension(DescCharWidth, DescCharHeight));
            // setSize(new Dimension(DescCharWidth, DescCharHeight));
            addKeyListener(this);
            addFocusListener(this);
            fixTAB();
        public IicTextAreaSwift(int _rows, int _columns)
              super(_rows, _columns);
              // HA this constructor is for this field not in a scroll pane
              setDisabledTextColor(Color.gray);
              rows            = _rows;
              columns         = _columns;
              setRows(_rows);
              maxTextAllowed  = _rows * _columns;
              setBorder(new BevelBorder(BevelBorder.LOWERED));
              setLineWrap(true);
              setWrapStyleWord(true);
              Font fixedFont = new Font("Courier", Font.PLAIN, 12);
              setFont(fixedFont);
              FontMetrics fm = getFontMetrics(fixedFont);
              DescCharWidth = fm.charWidth('W') * (_columns + 1);
             //  DescCharHeight = fm.getHeight() * 4 ;
              DescCharHeight =  DEFAULT_LABEL_HEIGHT * 3;
              setPreferredSize(new Dimension(DescCharWidth, DescCharHeight));
              // setSize(new Dimension(DescCharWidth, DescCharHeight));
              addKeyListener(this);
              addFocusListener(this);
              fixTAB();
        public Dimension getDimen()
              return new Dimension(     DescCharWidth, DescCharHeight);
         public void showKeys(JComponent component)
              // List keystrokes in the WHEN_FOCUSED input map of the component
              InputMap map = component.getInputMap(JComponent.WHEN_FOCUSED);
              printInputMap(map,"WHEN_FOCUSED");
              // List keystrokes in the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT input map of the component
              map = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
              printInputMap(map,"WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
              //list(map, map.keys());
              // List keystrokes in all related input maps
              //list(map, map.allKeys());
              // List keystrokes in the WHEN_IN_FOCUSED_WINDOW input map of the component
              map = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
              printInputMap(map,"WHEN_IN_FOCUSED_WINDOW");
              printActionMap( getActionMap() , "JTextArea");
              //list(map, map.keys());
              // List keystrokes in all related input maps
            // list(map, map.allKeys());
         public void fixTAB()
              Set newForwardKeys = new HashSet ();
              newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0, false));
              this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
              Set newBackwardKeys = new HashSet ();
              newBackwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK, false));
              this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newBackwardKeys);
              Set forwardKeys = this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    //          System.out.println ("Desktop forward focus traversal keys: " + forwardKeys);
              Set backwardKeys = this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    //          System.out.println ("Desktop backward focus traversal keys: " + backwardKeys);
             this.setFocusTraversalKeysEnabled(true);
         public static void printActionMap(ActionMap actionMap, String who)
         {     //     System.out.println("Action map for " + who + ":");
              Object[] keys = actionMap.allKeys();
              if (keys != null)
                   for (int i = 0; i < keys.length; i++)
                        Object key = keys;
                        Action targetAction = actionMap.get(key);
                   //     System.out.println("\tName: <" + key + ">, action: " + targetAction.getClass().getName());
         public static void printInputMap(InputMap inputMap, String heading)
              //System.out.println("\n" + heading + ":");
              KeyStroke[] keys = inputMap.allKeys();
              if (keys != null)
                   for (int i = 0; i < keys.length; i++)
                        KeyStroke key = keys[i];
                        Object actionName = inputMap.get(key);
                   //     System.out.println("\tKey: <" + key + ">, action name: " + actionName);
    public void paste()
    public void focusGained(java.awt.event.FocusEvent event)
              //System.out.println("Hman " + event.paramString());
         if(event.getOppositeComponent() != null)
              if(event.getOppositeComponent().getParent() != null)
                   if (findRoot(event.getOppositeComponent()) != null && findRoot(this) != null)
                        if ( isEnabled() && findRoot(event.getOppositeComponent()) == findRoot(this))
                        selectAll();
         public Component findRoot(Component _cc)
              while (_cc.getParent() != null)
                   cc = cc.getParent();
                   //System.out.println("Parent:" + _cc);
                   if (_cc instanceof TradeDetailForm)
                   return _cc;
              return null;
    public void focusLost(java.awt.event.FocusEvent event)
         Begin Nirmal 1: Requirements 3.1 issues.
         To fix: getValue() method never returns more than the rows.
         New method added to ensure user entered text never goes beyond Rows
    * Method to ensure the getValue() never returns more than the rows.
    * will return -1 if the rows are out of range
    * @param KeyEvent
    * @return int
    public int ensureNotBeyondRows(KeyEvent e)
              String[] s = getValue();
              if (s==null)
                   return 0;
              if (s.length>rows)
                   setText(retainText);
                   return -1;
              String str=getText();
              insert(e.getKeyChar()+"", getCaretPosition());
              s = getValue();
              setText(str);
              if (s.length>rows)
                   setText(retainText);
                   return -1;
              return 0;
         End Nirmal 1:
    // main Method
    // processComponentKeyEvent Method
    public void keyTyped(KeyEvent e)
         /* Naga */
              System.out.println("inside keyTyped");
              System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
         /*try
                   java.lang.Thread.sleep(2000);
              catch(InterruptedException ie)
         try {
    int curPos2 = getCaretPosition();
    int curLine2 = getLineOfOffset(curPos2);
    //System.out.println( "curline:" + curLine2 + " of " + rows);
    char[] tmp = {e.getKeyChar()};
    int curPos1 = getCaretPosition();
    int line1 = getLineOfOffset(curPos1) ;
    int startOfLine = getLineStartOffset(line1) ;
    if( curPos1 == startOfLine && line1 > 0)
    if ((tmp[0] == ':') || (tmp[0] == '-' )){
    // System.out.println("hman3");
    e.consume();
    return;
                   Begin Nirmal 2: Requirements 3.1 issues.
                   To fix: getValue() method never returns more than the rows.
                   New method added to ensure user entered text never goes beyond Rows
                   if (!isArrowKey(e) &&
                        (e.paramString().indexOf("Enter") == -1 ) &&
                        !isBackspaceKey(e)) {
                             int maxLimitFlg=ensureNotBeyondRows(e);
                             setCaretPosition(curPos2);
                             if (maxLimitFlg == -1)
                                  e.consume();
                                  return;
                   End Nirmal 2:
    // System.out.println("e.paramString()" + e.paramString());
    // System.out.println("place 2 " + e.paramString());
    if (!(StringFormatter.isValidSwift(tmp[0])) && !(functionKey(e)) && notMoveForward(e))
    // System.out.println("hman2 isaction" + e.isActionKey());
    // System.out.println("KeyTyped" + e.getKeyChar()+ e.getKeyText(e.getKeyCode()) + "/keycode" + e.getKeyCode() + "/modifiers" + e.getModifiers() );
    e.consume();
    return;
    int curPosInLine = -1;
    int firstPos = -1;
    if (getText().length() < maxTextAllowed ||
    (KeyCode == KeyEvent.VK_UP || KeyCode == KeyEvent.VK_BACK_SPACE))
    int curPos = getCaretPosition();
    if (!(functionKey(e)))
    e.setKeyChar( (new String( tmp ).toUpperCase()).toCharArray()[0]);
    curPos2 = getCaretPosition();
    curLine2 = getLineOfOffset(curPos2);
    //System.out.println( "curline:" + curLine2 + " of " + rows);
    if (curLine2 + 1 >= rows &&
    (KeyCode == KeyEvent.VK_ENTER ||
    KeyCode == KeyEvent.VK_DOWN) )
    // System.out.println("hman1");
    e.consume();
    return;
    else {
    String oldText = getText();
    // super.processKeyEvent(e);
    if (getNumberOfLines(getLineCount()) == -1 && !(functionKey(e)))
    setText(oldText);
    invalidate();
    setCaretPosition(curPos);
    } } catch (javax.swing.text.BadLocationException evt) {
    System.out.println("Bad Location Exception in processKeyEvent");
    public void keyPressed(KeyEvent e){
              //System.out.println("keyPressed" + e.getKeyCode()+ e.getKeyText(e.getKeyCode()));
                   retainText = getText();//retain always the latest text
                   /* Naga */
                   //System.out.println("retainText " + retainText);
                   System.out.println("inside keyPressed");
                   System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
                   /*try
                        java.lang.Thread.sleep(2000);
                   catch(InterruptedException ie)
    public void keyReleased(KeyEvent e){
              //System.out.println( "keyReleased" + e.getKeyCode()+ e.getKeyText(e.getKeyCode()));
         String []s = getValue();
         /* Naga */
         System.out.println(" inside keyReleased");
         System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
         /*try
              java.lang.Thread.sleep(2000);
         catch(InterruptedException ie)
              /*try
                   System.out.println("s " + s[0]);
                   System.out.println("s " + s[1]);
                   System.out.println("s " + s[2]);
                   System.out.println("s " + s[3]);
              catch(Exception e1)
              //System.out.println("s.length " + s.length);
              //System.out.println("rows " + rows);
              if (s!=null && s.length>rows)
                   System.out.println("setting text");
                   //setText(retainText);
                   invalidate();
         public boolean isTab(KeyEvent e)
              if (e.paramString().indexOf("keyChar=Tab") == -1)
              return false;
              } else
                   return true;
         public boolean keepProcessing(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("keyChar=Backspace") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Left") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Down") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Up") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Delete") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Right") != -1 ) { return true; }
              return false;
         public boolean isArrowKey(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Left") != -1 ||
                   e.paramString().indexOf("Down") != -1 ||
                   e.paramString().indexOf("Up") != -1 ||
                   e.paramString().indexOf("Right") != -1 )
                   return true;
              return false;
         public boolean isBackspaceKey(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Backspace") != -1)
                   return true;
              return false;
         public boolean isDeleteKey(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Delete") != -1)
                   return true;
              return false;
    public boolean notMoveForward(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Backspace") == -1 &&
              e.paramString().indexOf("Left") == -1 &&
              // e.paramString().indexOf("keyText=Down") == -1 &&
              e.paramString().indexOf("Up") == -1 &&
              e.paramString().indexOf("Delete") == -1 ) { return true; }
              return false;
    // processKeyEvent Method
    public void processKeyEvent(java.awt.event.KeyEvent e)
    //     System.out.println( "processKeyEvent");
         /* Naga */
         System.out.println(" inside processKeyEvent");
         System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
                   if (e.paramString().indexOf("KEY_PRESSED") != -1) {
                        KeyText=e.paramString();
                   } else {
                        KeyText="";
                   KeyCode=e.getKeyCode();
    int filledRows = (getText().length()-1)/columns + 1;
    if (KeyCode == KeyEvent.VK_ENTER && filledRows >= rows)
    return;
    try {
                   if (isArrowKey(e) || isBackspaceKey(e) || isDeleteKey(e)) {
                        super.processKeyEvent(e);
                        return;
    int curPos2 = getCaretPosition();
    int curLine2 = getLineOfOffset(curPos2);
    // System.out.println( "curline:" + curLine2 + " of " + rows);
    if (curLine2 + 1 >= rows &&
    (KeyCode == KeyEvent.VK_ENTER ||
    KeyCode == KeyEvent.VK_DOWN) )
                             //System.out.println("hman5");
    e.consume();
    return;
    int curPosInLine = -1;
    int firstPos = -1;
    if (getText().length() < maxTextAllowed)
    int curPos = getCaretPosition();
    curPos2 = getCaretPosition();
    curLine2 = getLineOfOffset(curPos2);
    int curlinepos = getLineStartOffset(curLine2) ;
                   if ( (curLine2 + 1 == rows) && (curPos2 - curlinepos >= getColumns() - 1) && notMoveForward(e))
                        e.consume();
    return;
    if ((curLine2 + 1 >= rows &&
    (KeyCode == KeyEvent.VK_ENTER ||
    KeyCode == KeyEvent.VK_DOWN) ))
    // System.out.println("hman6");
    e.consume();
    return;
    } else {
    String oldText = getText();
    // System.out.println("hman7");
    super.processKeyEvent(e);
    if (getNumberOfLines(getLineCount()) == -1 && !(functionKey(e)))
    // System.out.println("hman8");
    setText(oldText);
    invalidate();
    setCaretPosition(curPos);
    } } catch (javax.swing.text.BadLocationException evt) {
    System.out.println("Bad Location Exception in processKeyEvent");
    // processFunctionalKeys Method
    public boolean processFunctionalKeys(java.awt.event.KeyEvent e)
    // System.out.println( "processFunctionalKeys");
    if (KeyCode == KeyEvent.VK_BACK_SPACE ||
    KeyCode == KeyEvent.VK_ESCAPE ||
    KeyCode == KeyEvent.VK_PAGE_UP ||
    KeyCode == KeyEvent.VK_PAGE_DOWN ||
    KeyCode == KeyEvent.VK_END ||
    KeyCode == KeyEvent.VK_HOME ||
    KeyCode == KeyEvent.VK_LEFT ||
    KeyCode == KeyEvent.VK_UP ||
    KeyCode == KeyEvent.VK_RIGHT ||
    KeyCode == KeyEvent.VK_DOWN ||
    KeyCode == KeyEvent.VK_DELETE
    //System.out.println("Process the KEY getkey:" + e.getKeyChar() + "/getcode:" + e.getKeyCode());
    super.processKeyEvent(e);
    return true;
    else
    return false;
    public boolean functionKey(java.awt.event.KeyEvent e)
    // System.out.println( "functionKey");
    if (KeyCode == KeyEvent.VK_BACK_SPACE ||
    KeyCode == KeyEvent.VK_ESCAPE ||
    KeyCode == KeyEvent.VK_PAGE_UP ||
    KeyCode == KeyEvent.VK_PAGE_DOWN ||
    KeyCode == KeyEvent.VK_END ||
    KeyCode == KeyEvent.VK_HOME ||
    KeyCode == KeyEvent.VK_LEFT ||
    KeyCode == KeyEvent.VK_UP ||
    KeyCode == KeyEvent.VK_RIGHT ||
    KeyCode == KeyEvent.VK_DOWN ||
    KeyCode == KeyEvent.VK_DELETE
    //System.out.println("Process the KEY getkey:" + e.getKeyChar() + "/getcode:" + e.getKeyCode());
    //super.processKeyEvent(e);
    return true;
    else
    return false;
    // getLineCount Method - Returns -1 if number of lines is not between 1 to 4.
    /* This method return -1 if number of lines is not between 1 to 4.
    Pass in getLineCount() to get number of lines for all elements.
    JTextArea separates elements by new line character.
    BnyTextArea treats each row as a line.
    public int getNumberOfLines(int elementCount)
    int lineCount = 0;
    int startPos = 0;
    int endPos = 0;
    for (int i = 0; i <= elementCount - 1; i++) {
    lineCount = lineCount + getLineCountOfElement(i);
    if (lineCount == -1 || lineCount > rows) {
    lineCount = -1;
    break;
    return lineCount;
    // getSpacePos Method - this method finds the first position of space found.
    public int getSpacePos(int pos)
              Begin Nirmal 3: Requirements 3.1 issues.
              Modified the end limit from 0 to pos-columns,
              so that to avoid the return index value from previous lines
              int endLimit=pos-columns;
              if (endLimit<0) {
                   endLimit=pos;
    for (int i = pos; i > endLimit; i--) {
    if (getText().charAt(i) == ' ' || getText().charAt(i) == '\n') { // 11/14/03 Eaten treat \n as space
                        return i;
    return -1;
              End Nirmal 3:
    // getLineCountOfElement Method - returns -1 if number of lines is not between 1 to 4.
    public int getLineCountOfElement(int line)
    int lineCount = 1;
    try {
    int startPos = getLineStartOffset(line) ;
    int endPos = getLineEndOffset(line) ;
    if (moreThanNumOfColumns(startPos, endPos)) {
    lineCount = 2;
    startPos = getSpacePos(startPos+columns);
    if (startPos != -1 && moreThanNumOfColumns(startPos+1,endPos)) {
    lineCount = 3;
    startPos = getSpacePos(startPos+columns);
    if (startPos != -1 && moreThanNumOfColumns(startPos+1,endPos)) {
    lineCount = 4;
    startPos = getSpacePos(startPos+columns);
    if (startPos != -1 && moreThanNumOfColumns(startPos+1,endPos)) {
    return -1;
    } catch (javax.swing.text.BadLocationException e) {
    System.out.println("Bad Location Exception in getLineCountOfElement");
    return lineCount;
    // moreThanNumOfColumns Method
    public boolean moreThanNumOfColumns(int startPos, int endPos)
    if ((endPos - startPos) > (columns + 1))
    return true;
    else
    return false;
    // getNewLineCount Method
    public int getNewLineCount()
    int count = 0;
    boolean rc = true;
    int pos = getText().indexOf(KeyEvent.VK_ENTER, 0);
    if (pos == -1)
    rc = false;
    else
    count++;
    while (rc) {
    pos = getText().indexOf(KeyEvent.VK_ENTER, pos+1);
    if (pos == -1)
    rc = false;
    else
    count++;
    return count;
    // getValue Method
    public String[] getValue()
    // System.out.println(getText());
    int lines = getLineCount();
    int spacePos = 0;
    String str = new String();
    Vector strings = new Vector();
    boolean newLine=true;
    /*Nirmal : this boolean is to add the empty only in new line.
    To avoid those lines which end with \n
    if (getDocument().getLength() > 0) {
    for (int i = 0; i < lines; i++) {
                        newLine=true;
    try {
    int startPos = getLineStartOffset(i) ;
    int endPos = getLineEndOffset(i) + 1;
    /* Naga */
    //System.out.println("startPos " + startPos);
    //System.out.println("endPos " + endPos);
    //System.out.println(i + "HHMAN startPos = " + getLineStartOffset(i));
    //System.out.println(i + "HHMAN endPos = " + getLineEndOffset(i));
    while (moreThanNumOfColumns(startPos,endPos)) {
                                  newLine=false;
    int tempEndPos = 0;
    tempEndPos = startPos + columns;
    System.out.println("tempEndPos " + tempEndPos + " columns " + columns);
    spacePos = getSpacePos(tempEndPos);
    if (spacePos == -1) {
    if (startPos >= getDocument().getLength())
    break;
    else {
    if (tempEndPos >= getDocument().getLength())
    spacePos = getDocument().getLength();
    else {
    spacePos = startPos + columns;
    str = getText().substring(startPos,spacePos);
    if (!(str.trim().equals(""))) {
                                       strings.addElement(str.trim());
    startPos = spacePos;
                             if (startPos < endPos) {
         str = getText().substring(startPos,endPos - 1).trim();
         if(str!=null) {
              if(str.trim().length()>0) {
                                            strings.addElement(str);
                                            continue;
                                       } else {
                                            if(newLine) {
                                                 strings.addElement(str);
    /*Nirmal commented the below lines to fix existing issue
    of adding even empty lines entered in textbox */
    //if ((str==null) || (str.length()==0)) continue;
    //if (!(str.trim().equals(""))) strings.addElement(str);
    } catch (javax.swing.text.BadLocationException e) {
    System.out.println("Bad Location Exception in getValue");
    String[] strs = new String[strings.size()];
    strings.copyInto(strs);
    return strs;
    } else
    return null;
         public void clear() {
    setText("");
    // invalidate();
    // repaint();
    // fixTAB();
    public int getColumnsX()
    if (columnLimits != null)
    int curPos = getCaretPosition();
    //System.out.println("getCaretPosition()" + curPos);
    if (curPos > 0)
    for (int i = 0;i < columnLimits.length;i++)
    curPos = curPos - columnLimits[i];
    if (curPos < 1)
    //System.out.println("getNumberOfLines(curElem)" + i);
    return columnLimits[i];
    } else
    return columns;
    return 0;
         public void setRowLimitX(int rows,int columns)
    maxTextAllowed = rows * columns;
    setRows(_rows);
    rows = _rows;
    columns = _columns;
    setFont(fixedFont);
    setBorder(new BevelBorder(BevelBorder.LOWERED));
    setLineWrap(true);
    setWrapStyleWord(true);
    Font fixedFont = new Font("Courier", Font.PLAIN, 12);
    FontMetrics fm = getFontMetrics(fixedFont);
    int width = fm.charWidth('W') * (35 + 1);
    int height = DEFAULT_LABEL_HEIGHT * 3 ;
    setPreferredSize(new Dimension(width, height));
    public void setEditable(boolean editable)
    super.setEditable(editable);
    super.setEnabled(editable);
    setFocusable(editable);
    if (editable)
    setForeground(Color.black);
    else
    setForeground(Color.gray);
    fixTAB();
    // add your data members here
    // add your data members here
    private int rows = 0;
    private int columns = 0;
    private int[] columnLimits = null;
    private int maxTextAllowed = 0;
    private Font fixedFont = new Font("Courier", Font.PLAIN, 12);
    public final static int LEFT_LABEL_WIDTH = 100;
         public final static int DEFAULT_LABEL_HEIGHT = 20;

    You posted way too much code. 90% of the code is not related to the "backspace" problem. We want compileable and executable code, but only that code that is relevant to the problem.
    Anyway, instead of handling KeyEvents you should read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings for the recommended approach.
    Also you may want to check out this posting which has some information on the backspace KeyStroke:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566748

  • Problem with JTextArea wanting to resize itself

    First, here is a program that will create the situation in which this error occurs:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class Example extends JFrame
        private final String TITLE       = "Example";
        private final int    WIDTH       = 640;
        private final int    HEIGHT      = 480;
        private JMenuBar     menuBar     = new JMenuBar();
        private JMenu        modeMenu    = new JMenu( "Mode" );
        private JMenuItem    mode1       = new JMenuItem( "Mode 1" );
        private JMenuItem    mode2       = new JMenuItem( "Mode 2" );
        private JTextArea    textArea1   = new JTextArea();
        private JTextArea    textArea2   = new JTextArea();
        private JScrollPane  scrollPane1 = new JScrollPane( textArea1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        private JScrollPane  scrollPane2 = new JScrollPane( textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        private JPanel       everything  = new JPanel( new BorderLayout() );
        private JPanel       modeOptions = new JPanel();
        private int          modeInt     = 1;
        public Example ()
            setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            setSize( WIDTH, HEIGHT );
            setLocation( 100, 100 );
            setResizable( true );
            mode1.addActionListener( new ActionListener()
                public void actionPerformed ( ActionEvent e )
                    modeInt = 1;
                    updateModeOptions();
            mode2.addActionListener( new ActionListener()
                public void actionPerformed ( ActionEvent e )
                    modeInt = 2;
                    updateModeOptions();
            modeMenu.add( mode1 );
            modeMenu.add( mode2 );
            menuBar.add( modeMenu );
            setJMenuBar( menuBar );
            updateModeOptions();
            initializeLayout();
        private void updateModeOptions ()
            modeOptions.removeAll();
            switch ( modeInt )
                case 1:
                    JLabel text = new JLabel( "Change to Mode 2 to see the text areas shrink." );
                    modeOptions.add( text );
                    setTitle( TITLE + " - " + "Mode 1" );
                    break;
                case 2:
                    JPanel temp = new JPanel();
                    JLabel text = new JLabel( "Text in a JPanel, to show change in text area size." );
                    temp.add( text );
                    modeOptions.add( temp );
                    setTitle( TITLE + " - " + "Mode 2" );
                    break;
                default:
                    break;
            setVisible( true );
        private void initializeLayout ()
            JPanel panel1 = new JPanel( new BorderLayout() );
            JPanel panel2 = new JPanel( new BorderLayout() );
            JPanel everythingCenterPanel = new JPanel();
            everything.setBorder( BorderFactory.createEtchedBorder() );
            panel1.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Scroll Pane 1" ) );
            panel2.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Scroll Pane 2" ) );
            everythingCenterPanel.setLayout( new BoxLayout( everythingCenterPanel, BoxLayout.Y_AXIS ) );
            panel1.add( scrollPane1 );
            panel2.add( scrollPane2 );
            everythingCenterPanel.add( panel1 );
            everythingCenterPanel.add( modeOptions );
            everythingCenterPanel.add( panel2 );
            everything.add( everythingCenterPanel );
            add( everything );
        public static void main ( String[] args )
            new Example().setVisible( true );
    }Try changing between Mode 1 and Mode 2 (via the Mode menu) to see how the text areas resize as the object between them grows and shrinks. This behavior is correct.
    What is incorrect is what happens when the user enters a large amount of text into one of the text boxes (6 or 7 lines of text should be enough to create the problem) and switches between modes.
    I've tried using the getSize and setSize methods of various components at various points in the program but none seem to work effectively. The closest thing I've been able to do is to keep the JTextAreas, the JScrollPanes, and the JPanels holding them to remain the same sizes, but the text still pushes the panel between the JTextAreas down (and possibly out of) the window, leaving a blank area between the edge of the JPanel containing the JScrollPane and the JPanel in the center.
    The JPanels containing the JScrollPanes must be able to resize correctly as the user resizes the window, so a constant size would not work in this situation.
    Any help is greatly appreciated.

    What is incorrect is what happens when the user enters a large amount of text into one of the text boxes I don't notice anything happening when I add text to the text area. The scrollbars appear as is expected. The only difference for me when I switch between mode 1 and 2 is that the center panel changes in size slightly. This is because the panel is using a FlowLayout which by default has a 5 pixel vertical gap between each component. This is easily fixed by using:
    JPanel temp = new JPanel( new FlowLayout(FlowLayout.CENTER, 5, 0) );I know you tested using JDK1.5 since I had to make the following change in order to get the example to work:
    getContentPane().add( everything );
    So maybe this is a version problem since I don't notice anything out of the ordinary other than what I already mentioned.

  • JSplitPane problem with JTextArea

    The following piece of code has the problem in it. When you resize the splitpane you won't be able to decrease the size because of the setLineWrap(true).
    I am also wondering why the button in the bottom moves (and how do I stop it from moving) when the splitpane is made bigger.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    public class HMI extends JFrame {
         private JPanel map;
         private LeftMenu leftMenu;
         private JSplitPane split;
         public HMI(String title) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                   SwingUtilities.updateComponentTreeUI(this);
              catch (Exception ex) {System.out.println("Look and feel does not exist");}
              map = new JPanel();
              leftMenu = new LeftMenu();
              split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftMenu,map);
              setLayout(new BorderLayout());
              add(split, BorderLayout.CENTER);
              split.setOneTouchExpandable(true);
              split.setBorder(BorderFactory.createEmptyBorder());
              setSize(1024,768);
              setLocationRelativeTo(null);
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
    //NESTED
    public class LeftMenu extends JTabbedPane {
         TabLogg logg;
         public LeftMenu() {
              logg = new TabLogg();
              addTab("Logg",null,logg,"Visar loggar av information f�r kartan");
    //NESTED
    public class TabLogg extends JPanel {
         private JButton reset = new JButton("Clear logg");
         private TitledBorder border = BorderFactory.createTitledBorder("Logg");
         private JTextArea text = new JTextArea();
         public TabLogg() {
              setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
              text.setLineWrap(true);
              text.setEditable(false);
              reset.setAlignmentX(Component.RIGHT_ALIGNMENT);
              add(text);
              add(reset);
              text.setText("testststg sd sdgs gsdg sd gs gsdgsdg");
         public static void main (String[] arg) {
              HMI human = new HMI("V�ltnavigeringssystem Interface - Ny");
    }

    I want the button to stay alligned to the very left. Read the Swing tutorial on [How to Use Box Layout|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html] for an explanation and example of how the alignment of components works.
    Also, use the following to maximize the frame:
    //setSize(1024,768);
    setExtendedState(JFrame.MAXIMIZED_BOTH);

  • Native -- DataFlavor clipboard problem

    I'm trying to access vim specific clipboard data (to get visual block info). This is on windows XP (unix is next) I've registered the formats with addFlavorForUnencodedNative, see java code below. But when I look at all the clipboard flavors, when clipboard contains vim stuff, no vim flavors show up, see output.
    Any ideas of what/where the problem might be?
    Thanks,
    -ernie
    In vim, from its os_win32.c, there is
        clip_star.format = RegisterClipboardFormat("VimClipboard2");
        clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");and when a vim copy to clipboard command is issued, in vim's os_mswin.c. Note that cbd->format is clip_start.format, returned from RegisterClipboardFormat above.
    SetClipboardData(cbd->format, hMemVim);
    SetClipboardData(CF_UNICODETEXT, hMemW) != NULL)
    SetClipboardData(CF_TEXT, hMem);When I run the java program I get the following output. First are the mimetype of the 3 native flavors I added; in cb.getAvailableDataFlavors() none of them appear in the 27 flavors available.
    VimClipboard application/vimclipboard; class=java.nio.ByteBuffer
    VimClipboard2 application/vimclipboard2; class=java.nio.ByteBuffer
    VimRawBytes application/vimrawbytes; class=java.nio.ByteBuffer
    27 flavors
    application/x-java-text-encoding; class="[B"
    application/x-java-serialized-object; class=java.lang.String
    ...Here's the java code that is not finding the vim clipboard native data
    /* Main.java; access vim's clipboard */
    package vimclipapp;
    import java.awt.Toolkit;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.FlavorMap;
    import java.awt.datatransfer.SystemFlavorMap;
    public class Main {
        static DataFlavor VimClipboard = addFlavor("VimClipboard");
        static DataFlavor VimClipboard2 = addFlavor("VimClipboard2");
        static DataFlavor VimRawBytes = addFlavor("VimRawBytes");
        static DataFlavor addFlavor(String cbName) {
            DataFlavor df = null;
            FlavorMap fm = SystemFlavorMap.getDefaultFlavorMap();
            SystemFlavorMap sfm = (SystemFlavorMap) fm;
            try {
                df = new DataFlavor(  "application/"
                                    + cbName
                                    + "; class=java.nio.ByteBuffer");
            } catch (ClassNotFoundException ex) { ex.printStackTrace(); }
            System.err.println(cbName + " " + df.getMimeType());
            sfm.addFlavorForUnencodedNative(cbName, df);
            sfm.addUnencodedNativeForFlavor(df, cbName);
            return df;
        public static void main(String[] args) {
            Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
            if(cb.isDataFlavorAvailable(VimClipboard2))
                System.err.println("VimClipboard available");
            DataFlavor dfa[] = cb.getAvailableDataFlavors();
            System.err.println("\n" + dfa.length + " flavors\n");
            for (DataFlavor df : dfa) {
                System.err.println(df.getMimeType());
    }

    Are you using Gmail?
    Try deleting the email profile, tap battery, tap restart, go into email and reinstall the profile.

  • Problem update JTextArea with message from thread

    I have a JTextArea to present the actually status of an running thread. The thread sends strings like: System.out.println("Reading in new message...");to the standardoutput.
    The problem is, that my application freezes when it should update the JTextArea. Any idea and what type of actionListener is recommend to use for the JTextArea?
    try
       BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
       statusmsg = breader.readLine();
       statusTextArea.append(statusmsg);
    catch (Exception e){};Cheers

    In general, you can't update the Swing stuff from "side" threads. Side threads talk with the Swing event thread by creating Runnable objects which contains the necessary data (in your case, for instance, the JTextArea or its parent panel/window, and the text to append), and then invoking SwingUtilities.invokeLater() to have this object run() method called by the Sing event thread. See:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

  • A problem with JTextArea.write()

    hi, I'm writting some code about reading content of a TextArea by use the method JTextArea.write().
    when the content is short, that will be ok, but the content is too long, my thread seems to be dead. and NetBeans's debuger shows nothing, just unresponse.
    can someone to point out my problem in the code below?
    textSource.write(bfw); //textSource is extends from JTextArea, when content in it is too large, dead here
    private void output2textResult() {
            Runnable myThread = new Runnable() {
                public void run() {
                    // component.doSomething();
                    final String source = txtFldSource.getText();
                    final String destination= txtFldDestination.getText();
                    String tmp;
                    try{
                        PipedWriter pipOut = new PipedWriter();                  
                        BufferedWriter bfw = new BufferedWriter(pipOut);   //I wrapped the pipOut with the BufferedWrite
                        PipedReader pipIn = new PipedReader(pipOut);
                        BufferedReader bfr= new BufferedReader(pipIn);
    //problem line below
                        textSource.write(bfw);   //textSource is extends from JTextArea, when content in it is too large, dead here  
                        while(bfr.ready()){
                            tmp = bfr.readLine();
                            tmp.replaceAll(source, destination);
                            textResult.append(tmp+"\n");
                        bfr.close();
                        pipIn.close();
                        pipOut.close();
                    }catch(IOException e){
                        System.out.println(e);
            SwingUtilities.invokeLater(myThread);

    This won't work. Pipes are for use between threads. The implication of what you're doing in a single thread is that the pipe is somehow capable of holding the entire source text (which it isn't). In other words you're just trying to buffer it, so you may as well just get all the source text as a String and do your magic on it directly.

  • Mix of Arabic and English causes problems in JTextArea

    I have a JTextArea which displays HTML of an Arabic web page. So it's essentially a mix of English and Arabic. In the JTextArea, with columns set to 30, certain text just disappears instead of wrapping properly. The weird thing is that if I copy the invisible text and paste it into Notepad, then I can see it in Notepad. If I change the number of columns to 40, everything displays fine. Any ideas?

    It seems that Arabic is not the problem here. It is something to do with tabs. All the lines that disappear begin with 5 tabs. If I remove one tab so that they begin with 4 tabs, then they appear fine in the JTextArea

  • Java - system clipboard problem

    I'm trying to put text from a java program to the system clipboard (OS) and I can't make it work.
    I've included a small code example in this post.
    import java.awt.datatransfer.*;
    import java.awt.*;
    import java.awt.Toolkit.*;
    class ClipTest{
    public static void main(String[] args){
    new ClipTest();
    public ClipTest(){
    StringSelection clip = new StringSelection("hello");
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(clip,clip);
    System.exit(0);
    After running the program I would expect to have "hello" on my System clipboard. But I don't. Nothing has been transfered to the clipboard.
    I'm running java1.3.1 on IRIX and I have tryed Linux as well.
    Am I doing something wrong here? Please enlighten me.

    That's a thought. but take this code example though:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyTextArea extends JTextArea implements ActionListener{
    JTextArea m_txt;
    JPopupMenu m_menu;
    public MyTextArea(){
    super();
    m_txt=this;
    addMouseListener(new RightMouseListener());
    m_menu = new JPopupMenu("Menu");
    JMenu item = new JMenu("Edit");
    m_menu.add(item);
    JMenuItem item1 = new JMenuItem("Copy");
    item1.addActionListener(this);
    item1.setActionCommand("copy");
    item.add(item1);
    class RightMouseListener extends MouseAdapter{
    public void mouseClicked(MouseEvent e){
    if(e.getModifiers()==InputEvent.BUTTON3_MASK){
    m_menu.show(m_txt, e.getX(),e.getY() );
    public void actionPerformed(ActionEvent e){
    if (e.getActionCommand().equals("copy")) {
    copy();
    If you use this component in a dialog or something, type some text in it, make a selection, righclick and choose copy from the edit menu, I get the same result, and I guess it will work at your Windows platform?

  • Clipboard problem in CS5

    We often have to copy images in Word documents and paste them into a new file in Photoshop.
    Hitting New... in CS4 Photoshop opens a blank file of the correct size and resolution to paste in the clipboard file.
    CS5 cuts the file down to a tiny size and resolution.
    eg a 26MB file on tghe clipboard ends up as a 350k file when pasted.
    Any idea whats going on and how to fix it?

    When copied, 'Show Clipboard' does not show a pic....says it is RTF.
    Pastes perfectly into Text Edit and into Photoshop (CS4)
    Just CS5 PS seems to have a problem with it.
    We dont use Word except to extract stuff from files people send us and our copy of Word X is rather old.
    Maybe therein lies the problem.
    I will try with a newer version of Word.
    Incidentally, experimenting...printing a pdf from the Word file and then copying and pasting from the PDF works fine... copy from a pdf puts a tiff on the clipboard.
    But that is a pain so for the time being we will carry on using PS CS4 for this until a better solution comes up.

  • Clipboard problem

    All, I haven't been able to find such a topic so I assume I am the first one to ask, sorry if not...
    My problem is that the clipboard doesn't work between several applications :
    Camino -> mail
    Word -> mail
    Camino -> Text
    Smultron -> mail
    The clipboard keeps the previous text copied for Text or mail and doesn't paste the text that I have just copied but pastes it correctly in word, smultron or other applications...
    How is it possible with the best OS in the world that I can not copy paste from my browser to a simple mail ?? Do you have a solution to solve this issue or am I the first one experiencing bugs with the clipboard ?
    Thank you in advance for your help.

    HI and Welcome to Apple Discussions...
    *"How is it possible with the best OS in the world that I can not copy paste from my browser to a simple mail ??"*
    It's your 3rd party software, not the Mac OS X.
    Read "a brody's post here regarding 10.6 and 10.6.1
    http://discussions.apple.com/thread.jspa?messageID=10180165#10180165
    Carolyn

Maybe you are looking for

  • How to hook up a Laserwriter 16/600 so it works with computers running Mac OS 10.6 or greater.

    I am using a MacBook Pro 2.4 Ghz. I am using an Apple  1Tb Time Capsule as my source for the internet and "router" (I don't know if I'm using the terminology correctly, so if you need clarification, ask away). I have that Time Capsule connected to my

  • IPlanet Error - URGENT HELP Required

    Hi All, I am facing a problem with a deployed Application on iPlanet 6.0 on Windows 2000 Server. The Application works fine but after a couple of days it starts chewing up a lot of memory on the Windows box and ultimately hangs. The KJS logs have the

  • Umstieg von PSE 11 zu 12

    Hallo Leute, ich bin völlig neu und finde nirgends im Forum einen Hinweis auf meine Fragen und weiß auch nicht, ob meine Fragen hier richtig sind. Falls nicht, liebe(r) Mod, bitte verschieben. Ich nutze PSE 11 und habe nun die neue Version 12 gekauft

  • Signature images showing up as attachments.

    This is a mild annoyance. When I receive an email message from co-workers with images in their signatures, they show up as attachments. Sometimes I read a message thinking I need to download something and it's just the company logo. Is there a way to

  • Lightroom for team

    How can I share my photo and libraries with my team? We need of multilple licences for Lightroom?