Append text on dropping in jTextArea

Hello forum members;
I need help for appending some text while dropping in a text area.
My requirement is :
I have a jtextfield and jtextarea.I have to drag the texts from the text field and drop on textarea.
While dropping text from text field to textarea the text will move to textarea and then if the user will drag again the text from the textfield and drop on the textarea then the newly dragged text will append /add on the text at the end with a semicolon(;) .
For example :-
if the textfield contains text is "redtext" and drop for fist
time on text area the text area text will be "redtext" and when user drag for second time the text "bluetext " then the new text in the text area will be "redtext;bluetext"
and then if the user will drop "greentext " then the new text will be "redtext;bluetext;greentext" and so on. i.e a semicolon will be added at the end of the text.
Below is the code , please help me.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class AppendOnDrop extends JFrame{
     private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextField1;
     private javax.swing.JTextField jTextField2;
    private javax.swing.JTextArea jTextArea1;
      public AppendOnDrop() {
        super("AppendOnDrop Test");
        setSize(300, 100);
         jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField(2);
          jTextField2 = new javax.swing.JTextField(2);
        jPanel2 = new javax.swing.JPanel();
        jTextArea1=new javax.swing.JTextArea(10,10);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("100");
        jLabel1.setTransferHandler(new TransferHandler("text"));
        MouseListener listener = new DragMouseAdapter();
        jLabel1.addMouseListener(listener);
          jTextField1.setMaximumSize(new java.awt.Dimension(30, 28));
        jTextField1.setDragEnabled(true);
          jTextField1.setTransferHandler(new TransferHandler("text"));
          jTextField2.setMaximumSize(new java.awt.Dimension(30, 28));
        jTextField2.setDragEnabled(true);
          jTextField2.setTransferHandler(new TransferHandler("text"));
          jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Drag")));          
        jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.X_AXIS));
        jPanel1.add(jLabel1);
         jPanel1.add(jTextField1);
          jPanel1.add(jTextField2);
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Drop"));
        jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.X_AXIS));
          jPanel2.add(jTextArea1);
        getContentPane().add(jPanel1, BorderLayout.WEST);
        getContentPane().add(jPanel2, BorderLayout.EAST);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
     private class DragMouseAdapter extends MouseAdapter {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent)e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
       public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AppendOnDrop().setVisible(true);
}Thanks

Thanks very much hiwa;
This code snippest helped me a lot.This is working fine.
But on the first drag also the semicolon appended in the jTextArea. How to avoid the appending of semicolon for the first drag , is there any method for it i.e while user will drop for the first time the semicolon will not be appended but while drop for second time onwords the semicolon will be appended.
And application requirement is bit changed .i.e
I have a jlabel and a jtext area (as mentioned before).But now to make the functionality easy for user ,,
the user will only drag the label not the text from the text field and then the corresponding texts from the text field will move with the label dragging and dropped on the text area i.e not the jlabel value will dropped only the text will drop on text area.
For eexample:
if the label value is 100 and the text fild contains the texts as "red" , if the user will drag the label i.e 100 the text "red" will be dragged and while dropping to text area the texts only from the text field i.e "red" will be dropped but 100 will not be dropped any where.
please help me
Thanks & Regards
Mahenda

Similar Messages

  • Drag and drop to JTextArea

    Hi,
    I've implemented Drag and drop with a JTextArea as target. It also works fine.
    At the moment I use drag'n'drop for opening files I've dragged from Windows Explorer to my JTextArea. Now I want to extend my drop so I can also drop any text alternatively into my JTextArea. Also still no problem.
    But now I want my droped text to be inserted at the actual mouse position (like in e.g. Windows Wordpad). I don't just want to insert at the actual caret position or simple append the new text, I'd like to get the dropped text to the actual mouse position.
    I don't know how to get the caret position. I've seen you can get the x and y coordinates in the JTextArea using mousevents but I still don't know how to get the caret position from the x and y and I don't know if you can combine mouseEvents and dropTargetEvents.
    Maybe there's an other way, too? Any help would be great....

    Hello,
    I am also trying to do drag and drop into a JTextArea, as well as selecting and dragging text around in the JTextArea.
    Would you please be kind enough to show me some source code that does this, or at least point me in the direction of some useful links that might help me?
    My email is [email protected]
    Thanks in advance!
    Andrea

  • Problem in appending text in textfield

    When i am appending the text in Jtextfield component, It is appended in textField I can see these text on screen untill screen is filled. But when all rows is filled and any text is appended in textfield, i can not see these text. If i want to see these appended text, each time i need to scroll the screen. Can i see any appended text on screen without scrolling.

    Hi,
    Istead of JTextField , use JTextArea then it will give u this type of facility.
    rds
    Mohan Kumar
    i2 Technologies,
    Bangalore

  • Problem with append += text in Text Field

    Hi guys
    i have a problem with append text.
    I have one array which contain some city names, like CityArea=["NAME 1", "NAME2" ...etc];
    Then i have one String and one Text Field.
    Using for loop im getting right results. But when im running script again then im getting  same text again.
    F.ex.
    First time:
    City name: Name 1
    City name: Name 2
    Second time:
    City name: Name 1
    City name: Name 2
    City name: Name 1
    City name: Name 2
    I have tried to make TextField to and String to Null and delete it, but it's appearing again.. :/
    How to avoid this?
    Here is script:
    for (var i1:int = 0; i1 < CityArea.length; i1++)
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='32' COLOR='#ffffff'>        "+CityArea[i1]+"</FONT></P>";
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='5' COLOR='#ffffff'><BR></FONT></P>";
    _CityAreaTF1 = new TextField();
      _CityAreaTF1.border = true;
      _CityAreaTF1.wordWrap = true;
      _CityAreaTF1.multiline = true;
      _CityAreaTF1.selectable = false;
      _CityAreaTF1.antiAliasType = AntiAliasType.ADVANCED;
      _CityAreaTF1.name = "CityAreaTF1";
      _CityAreaTF1.embedFonts = true;
      _CityAreaTF1.htmlText = _CityAreaString1.toUpperCase();

    I think i found why.
    There was no problem with TextField.
    There was a problem with Array. "CityArea"
    So each time I executed script it added new string in Array. And that is because i got like:
    TextField
    City 1
    City 2
    City 1
    City 2
    Running this script is Ok:
    for (var i1:int = 0; i1 < CityArea.length; i1++)
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='32' COLOR='#ffffff'>        "+CityArea[i1]+"</FONT></P>";
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='5' COLOR='#ffffff'><BR></FONT></P>";
    But outside of this for loop there is another for loop for adding Cities in CityArray.
    I fixed it by adding empty array at the start of function
    function myFunc():void
    CityArea = [ ]; // Empty array fixed this issue
    // LOOP FOR ADDING SHOPS IN CITY AREA
    for (var j:int = 0; j < _Shops; j++)
    CityArea.push(_Shop);
    // FOR LOOP TO ADDING SHOPS IN STRING
    for (var i1:int = 0; i1 < CityArea.length; i1++)
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='32' COLOR='#ffffff'>        "+CityArea[i1]+"</FONT></P>";
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='5' COLOR='#ffffff'><BR></FONT></P>";
    Thank you for your help kglad

  • Need custom column widths in Append Text Table to Report

    I need to print reports with tables of different column widths specified for each column, as the contained fields vary in width from just 3 characters in one column to 40 characters in another.  Also we are trying to match the reports generated by a non-labview routine.  In the past I have been able to achieve this by editing the Append Table to Report vi, working my way through the inner hierarchy to replace the DBL numeric COLUMN WIDTH control with a DBL numeric array.  The innermost vi, Set Table Column Width, assigns the numeric to a property node in a for loop, so the change is simple: replace the scalor with an array and enable indexing on the for loop.  Of course, after each Labview upgrade, I've had to go back in and repeat these edits on the overwritten upgraded vi's.  This time there is a problem.  The new version of this toolkit is object oriented, and disturbing these vi's wrecks the class methods in a way I don't understand (mostly because I've had no dealings with object oriented programming) and which cannot be undone.  I recently tried this and after not being able to fix the problem even with phone support, I had to spend the next two days unistalling and reinstalling Labview!  I desperately need a way to achieve this functionality without killing the toolkit, which is used (in its original functionality) by another absolutely critical program.  PLEASE HELP!
    The hierarchy is as follows:
    NI report.lvclass:Append Table to Report (wrap)
    NI report.lvclass:Append Table to Report 
    NI Standard report.lvclass:Append Text Table to Report
    NI Standard report.lvclass:tables
    NI Report Generation Core.lvlibet Table Column Width

    There is a highly relevant thread under discussion here:
    http://forums.ni.com/ni/board/message?board.id=fea​tures&thread.id=429
    You may wish to read it and chime in as it is a discussion of LabVIEW's policy (and possible change in policy for the future) concerning the handling of non-palette VIs between LV versions.
    Rob Hingle wrote:
    > Is that to say NI will not be helping me with this?  Pretty disappointing lack of support, seems
    > like a terrible idea to go to object oriented if even your own application engineers can't figure
    > out such a simple fix.  Gotta give NI a huge thumbs down on this one, thanks for nothing.
    I doubt that it is a simple fix -- our AEs are generally top notch at figuring out solutions for customers -- if it were simple, my bet is they'd have solved it. Asking an AE to work around a bug is different from asking them to rearchitect the toolkit. You are asking them to add a feature that the new version of the toolkit is not
    designed to support. The difficulty in doing this is completely independent of the decision to use LabVIEW classes to implement the toolkit. If any piece of software is not designed with a particular use case in mind, what may be a simple tweak under one design may become a very hard problem under another design.
    In your case, the solution is very straightforward: Use the older version of the toolkit. Any time you create a custom modification of the VIs that ship with LV or one of its toolkits, you should make your own copy and have your VIs link against the copy. LabVIEW promises to maintain all the public functionality version over version. Usually we succeed at that. What we do not promise is to maintain our private implementation of that functionality. It is impossible for LabVIEW (or any other software library) to maintain all of its private internal operations while still continuing any development. Using a copy of the original VIs shields you from having to recode your changes every version (something you've already mentioned is a chore) and it guarantees that functionality that you relie upon does not disappear.
    I hope you are willing to be understanding of this situation and not hold it against the AEs working on this. They try hard to provide excellent customer service, and spend lots of time inventing custom solutions for our users.  This happens to be a situation where the correct fix is not to modify the new toolkit version to do something it wasn't designed to do but to modify your development process so that the problem is solved now and into the future. 

  • Bold text in drop down?

    Hi all
    Can we set bold text to drop down values. I am using drop down in table column. I want bold text at the time of defining values to dropdown or after selecting a value from drop down. Finally after selecting a value i want to display that text as BOLD. Could any help?
    Thanks,
    Madhan.

    Hi
    Not possible even if you use themes.
    i was thinking about using themes here but there also i have not found anything related to this particular requirment.
    thanks
    sarbjeet singh

  • TextPane always scroll to the bottom when append text

    How to avoid TextPane (inside scroll pane) to go to the bottom after append or set text. The current way I do is to scroll up again. This causes a noticable blink which I don't like very much. Could someone please point out if there is a setting I can do to say don't scroll?

    int pos = myTextArea.getCaretPosition();
    ...append text...
    myTextArea.setCaretPosition(pos);

  • Append text using SAVE_TEXT

    I'm trying to append text lines to the existing data for a given text id. And it seems to replace it each time.
    Is there a way to do it?
    This did not work....call replaces the text data.
        call function 'SAVE_TEXT'
          EXPORTING
            header   = thead
            insert   = 'I'
          TABLES
            lines    = tline
          EXCEPTIONS
            id       = 1
            language = 2
            name     = 3
            object   = 4
            others   = 5.
        if sy-subrc <> 0.
        endif.
        CALL FUNCTION 'COMMIT_TEXT'.
        COMMIT WORK.
    Thank you,
    Pam

    Hi Pam,
    You need to use FM READ_TEXT and FM EDIT_TEXT then use FM SAVE_TEXT.
    Hope this will help.
    Regards,
    Ferry Lianto

  • Ask about how to append text on next line

    I'm writing lingo about log file. For example, i would like
    to write like this when a new entry is appended:
    etc 3/29/2007 8:34 PM
    etc2 3/29/2007 8:34 PM
    Here is the lingo:
    on mouseUp
    if objectP(myFile) then set myFile = 0 -- Delete the
    instance if it already exists
    myFile = new(xtra "fileio") -- Create an instance of FileIO
    openFile(myfile, the moviePath&"try.txt",0) --Open the
    file with R/W access
    myVariable = readFile(myFile)
    setPosition(myfile,getLength(myFile)) -- Set position to end
    of file
    writeString(myFile, " " & "etc" & " " &
    _system.date() & " " & _system.time()) -- Append text to
    the file
    closeFile (myfile) -- Close the file
    myFile = 0 -- Dispose of the instance
    end
    The problem is the appended text is put together, instead of
    a line by a line. In fact, what I want is the appended text is put
    into next line everytime, not on the same line. Please help me to
    modify it, thanks.

    Try changing this line:
    writeString(myFile, " " & "etc" & " " &
    _system.date() & " " &
    _system.time()) -- Append text to the file
    to
    writeString(myFile, " " & "etc" & " " &
    _system.date() & " " &
    _system.time()&RETURN) -- Append text to the file
    Note that if you open the file inNotepad on a PC, it will
    look strange
    because of the way notepad handles line feeds. You can get
    around it by
    doing this:
    winReturn = NumToChar( 13 ) & NumToChar( 10 )
    writeString(myFile, " " & "etc" & " " &
    _system.date() & " " &
    _system.time()&winReturn) -- Append text to the file

  • Append text in a file?

    How can i append text in a text file?
    Thanks in advance.

    FileOutputStream has two constructors which allow appends: FileOutputStream(File file, boolean append)
    FileOutputStream(String name, boolean append)

  • Append text in file. and save it

    Append text in file.
    hi!
    i am new j2me Programer.
    1.i want to add(APPEND) the text in the file. i take this code form internet but i could succed Please help me.
    2.i want to save it in other directory like if i made folder on mobile device with name c:\Old i want to save file in that how could i ?
    kindly mention the Mistake.
    package FileConnection;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    import javax.microedition.io.*;
    * @author QTracker
    public class FileConnection extends MIDlet implements CommandListener {
    private boolean midletPaused = false;
    private Command exit, start;
    private Display display;
    private Form form;
    public FileConnection ()
    display = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 1);
    start = new Command("Start", Command.EXIT, 1);
    form = new Form("Write To File");
    form.addCommand(exit);
    form.addCommand(start);
    form.setCommandListener(this);
    private void initialize() { }
    public void startMIDlet() { }
    public void resumeMIDlet() {/
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
    Display display = getDisplay();
    if (alert == null) {
    display.setCurrent(nextDisplayable);
    } else {
    display.setCurrent(alert, nextDisplayable);
    public Display getDisplay () {
    return Display.getDisplay(this);
    public void exitMIDlet() {
    switchDisplayable (null, null);
    destroyApp(true);
    notifyDestroyed();
    public void startApp() {
    display.setCurrent(form);
    public void pauseApp() {
    midletPaused = true;
    public void destroyApp(boolean unconditional) {
    public void commandAction(Command c, Displayable d) {
    if (c == exit)
    destroyApp(false);
    notifyDestroyed();
    else if (c == start)
    try
    OutputConnection connection = (OutputConnection)
    Connector.open("file:\\c:\\myfile.txt;append=true", Connector.WRITE );
    OutputStream out = connection.openOutputStream();
    PrintStream output = new PrintStream( out );
    output.println( "This is a test." );
    out.close();
    connection.close();
    Alert alert = new Alert("Completed", "Data Written", null, null);
    alert.setTimeout(Alert.FOREVER);
    alert.setType(AlertType.ERROR);
    display.setCurrent(alert);
    catch( ConnectionNotFoundException error )
    Alert alert = new Alert(
    "Error", "Cannot access file.", null, null);
    alert.setTimeout(Alert.FOREVER);
    alert.setType(AlertType.ERROR);
    display.setCurrent(alert);
    catch( IOException error )
    Alert alert = new Alert("Error", error.toString(), null, null);
    alert.setTimeout(Alert.FOREVER);
    alert.setType(AlertType.ERROR);
    display.setCurrent(alert);
    }

    | Moderator advice: | Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose. |
    | | Please don't post in threads that are long dead and don't hijack another poster's thread. |
    | | Please don't solicit off forum communication by email. |
    | Moderator action: | The other four posts you made have been deleted. |
    db

  • Sharepoint duplicate append text inputs

    Hi,
    I’ve searched forums without solution for my problem.
    I have SharePoint 2010 custom list with multiple text fileds with append text and some checkboxes
    When I add some to text field it is normally displayed in append changes. But when I click checkbox it is recoded twice with same timestamp, and same content as  below
    jurica (1/1/2012, 13:00): comment2
    jurica (1/1/2012, 13:00): comment2
    jurica (1/1/2012, 13:05): comment1
    When I look in version history of item I get two version in 13:00 (when checkbox is clicked) and one in 13:05
    This second input isn’t added by workflow, but with form itself.
    Does anybody have idea what is making this odd behavior?

    Hi,
    According to your description, my understanding is that there are two same version history in the list after you click the checkbox.
    Did you have some workflow in the list?
    As the workflow may start after some field is added, so it will create another version.
    I suggest you check if the workflow change field value.
    Best regards,
    Zhengyu Guo
    Zhengyu Guo
    TechNet Community Support

  • TS3140 I tried to order a book on iPhoto but got the following message from apple :  the file contains text with drop shadows. As a result, Apple is unable to process your order"  Does anyone know what this means and how to fix it?   Thanks!!

    I tried to order a book on iphoto but got the following message from Apple  : "the file contains text with drop shadows.  As a result Apple is unable to process your order"  Does anyone know what this means and how to fix it?  Thanks!! 

    Hello Katiebell62
    Check out the troubleshooting steps to try and resolve your issue with purchasing a book through iPhoto.
    iPhoto: Difficulty submitting a book, card, or calendar order
    http://support.apple.com/kb/TS2516
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • Append text to logfile

    Can someone tell how to append text to a logfile?
    I use this function, but all existing text is always destoyed:
    function schrijf_naar_log(bestandsnaam){
    var log_bestand = File((Folder(bron_map)) + "/log.txt");
    log_bestand.open("e");
    log_bestand.writeln("\r\n" + bestandsnaam);
    log_bestand.close();
    Michel

    After opening for edit, you need to advance the "current position" in the file to the end using seek:
    log_bestand.seek(0.2);
    Dave

  • How to obtain richtextbox whose height adjusts to the appended text automatically without having scrollbar

    How to obtain richtextbox whose height adjusts to the appended text automatically without having scrollbar

    How to obtain richtextbox whose height adjusts to the appended text automatically without having scrollbar

Maybe you are looking for