• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

JTextField upper left corner

Hi Experts!!
How can i start writing into a JTextField from the uper left Corner, and keep APPENDING?

Thanks.
0
komlaaa
Asked:
komlaaa
2 Solutions
 
DrWarezzCommented:
What do you mean? Sorry.
Could you elaborate a bit more? :)

[r.D]
0
 
sciuriwareCommented:
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
 
CEHJCommented:
It might be better to use a different component, such as JTextArea for larger amounts of text
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
GrandSchtroumpfCommented:
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
 
GrandSchtroumpfCommented:
<:°)
0
 
CEHJCommented:
8-)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now