Solved

JTextField upper left corner

Posted on 2004-10-24
402 Views
Last Modified: 2006-11-17
Hi Experts!!
How can i start writing into a JTextField from the uper left Corner, and keep APPENDING?

Thanks.
0
Question by:komlaaa
    6 Comments
     
    LVL 9

    Expert Comment

    by:DrWarezz
    What do you mean? Sorry.
    Could you elaborate a bit more? :)

    [r.D]
    0
     
    LVL 24

    Expert Comment

    by:sciuriware
    The simplest way remains:
    void append(String text)
    {
         textfield.setText(textfield.getText() + text);
    }

    You might design a strategy to add newlines as <BR>  (HTML code).
    ;JOOP!
    0
     
    LVL 86

    Accepted Solution

    by:
    It might be better to use a different component, such as JTextArea for larger amounts of text
    0
     
    LVL 30

    Assisted Solution

    by:GrandSchtroumpf
    I think it's better to work on the Document.
    This way you don't need to set the entire text anytime you want to append something.
    You just append what you need to append to the Document.
    It should be much more efficient.

        JTextField myJTextField = new JTextField();
        Document myDocument = myJTextField.getDocument();

        myDocument.insertString(myDocument.getEndPosition().getOffset()-1, "hello ", null);
        myDocument.insertString(myDocument.getEndPosition().getOffset()-1, "cruel ", null);
        myDocument.insertString(myDocument.getEndPosition().getOffset()-1, "world ", null);

        System.out.println(myJTextField.getText());
    0
     
    LVL 30

    Expert Comment

    by:GrandSchtroumpf
    <:°)
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    8-)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    sumHeights  challenge 17 34
    JVM encoding. How to change encoding. 27 40
    array6 challenfge 6 30
    count11 challenge 6 17
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now