TextArea.setText ?????

I have several pieces of data i wish to output to the screen:
Instead of this:
textArea.setText("Milk amount = " + style.getMilk());
textArea.setText("Coffee Value = " + style.getCoffee());
textArea.setText("Water Value = " + style.getWater());How can I output them all at the same time without overwriting the other one?

You can do it either by using separate TextAreas (or maybe even better: Labels and TextFields) or by concatenating all the text and setting that in one go.JLabel milkLabel = new JLabel("Milk amount:");
JTextField milkField = new JTextField("0");
JLabel coffeeLabel = new JLabel("Coffee amount:");
JTextField coffeeField = new JTextField("0");
JLabel waterLabel = new JLabel("Water amount:");
JTextField waterField = new JTextField("0");
waterField.setText(style.getMilk());
coffeeField.setText(style.getCoffee());
waterField.setText(style.getWater()); or StringBuffer allText = new StringBuffer();
allText.append("Milk amount = ");
allText.append(style.getMilk());
allText.append("\nCoffee Value = ");  // \n moves to the next line
allText.append(style.getCoffee());
allText.append("\nWater Value = ");
allText.append(style.getWater());
textArea.set(allText.toString());

Similar Messages

  • Prevent scrolling to bottom of TextArea on setText()

    Hello. I have a dialog that displays simple text. I format the text the way I want and then set the text by calling textArea.setText(). I do this before I display the panel.
    If the text is beyond the view of the textArea the panel come up with the textArea scrolled all the way to the bottom. Is there a way to avoid auto scrolling or reset the scroll bar to the top when displaying the form?
    I must be missing a fundamental here. Please help.
    Thank you.

    textArea.setCaretPosition(0);

  • To limit number of chracters in textarea.

    hello all,
    please find below a small program to demonstrate how to limit number of charcaters in a textarea.
    i searchedthe forum and i actually got the technique from the forum. but when i put together a sa program it does not work.
    could anyone point out what is the problem in the small piece of code below.
    i am working on jdk 1.2.1
    thanx to all.
    // Example illustrating Limiting number of characters in text area.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class try1 extends JApplet {
    Container contentPane;
    JLabel label;
    JTA1 textarea;
    public void init() {
    // Get the handle on the applet's content pane.
         contentPane = this.getContentPane();
    // Create a text field and add a key listener to it.
         textarea = new JTA1(25);           // of 25 char width
    // Create a button object and register an action listener
         Button button = new Button("Clear");
         button.addActionListener(new ButtonListener());
    // Create a label with the titled border.
         label = new JLabel("Key Typed: NiL");
         label.setBorder(BorderFactory.createTitledBorder
    ("You pressed the Following Key"));
    // Add the text field and button to the applet's content pane.
         contentPane.setLayout(new BorderLayout());
         contentPane.add("North", textarea);
         contentPane.add(label);
         contentPane.add("South", button);
    // Get focus on text field.Note: You can do this only after you add the text field to the container
    class ButtonListener implements ActionListener {     // Create the button listener class.
         public void actionPerformed(ActionEvent e)      {
    // Reset the text components
         textarea.setText("");
    //Return the focus to the text field.
    class JTA1 extends JTextArea
         private int limit;
         public JTA1 ( int limit )
              this.limit = limit;
              addKeyListener( new LimitListener() );     
         class LimitListener extends KeyAdapter
              public void keyPressed( KeyEvent ke )
                   if( getText().trim().length() >= limit )
                   {     ke.consume(); //just consume KeyEvent

    Don't cross post. This question has been answered in your other post.

  • How to make my "notepad-program" clean the textarea when clicking on "ny"

    Hi!
    I'm having a problem cleaning the textarea when clicking on "ny" (new) in the menubar. What am I doing wrong? Could someone help me solve this problem?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class AnteckningsProgram
                        implements ActionListener{     
              static JFrame frame;
              static JTextArea textArea;
         public void skapaVisaGUI () {
              frame = new JFrame ("Anteckningsprogram");
             frame.setSize (340, 240);
             frame.setVisible (true);
             frame.setTitle ("Ra Anteckningsprogram");
             Toolkit          tk = Toolkit.getDefaultToolkit ();
             Image      bild = tk.getImage("r.png");
             frame.setIconImage(bild);
              JTextArea textArea = new JTextArea ();
             frame.add (textArea, "Center");
             JMenuBar cm = createMenuBar();       
             //frame.add(cm, BorderLayout.NORTH);     
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public     JMenuBar     createMenuBar () {
              JMenuBar     menyBar;
              JMenu          meny;
              JMenuItem     oppna;
              JMenuItem     quit;
              JMenuItem     ny;
              menyBar = new JMenuBar ();
              JMenu arkiv = new JMenu("Arkiv");
              oppna = new JMenuItem ("Oppna");
              quit = new JMenuItem("Quit");
              ny = new JMenuItem("Ny");
              ny.setActionCommand("Ny");
              ny.addActionListener(this);
              quit.setActionCommand("Quit");
              quit.addActionListener(this);
              //arkiv.setMnemonic(KeyEvent.VK_U);
              arkiv.add(oppna);
              arkiv.addSeparator();
              arkiv.add(quit);
              arkiv.addSeparator();
              arkiv.add(ny);
              menyBar.add(arkiv);
              frame.setJMenuBar(menyBar);     
              return menyBar;     
         public void actionPerformed(ActionEvent e) {
             if ("Ny".equals(e.getActionCommand())) {
                      createTextArea();
                 //annars går vi vidare till metoden quit
                 else {
                     quit();
         protected void quit() {
                 System.exit(0);
         protected void createTextArea() {
              JTextArea textArea = new JTextArea ();
              textArea.setText("fdfdsfdfsdf");
          public static void main(String[] args) {
                  //anroppar metoden createandshowGUI
                  AnteckningsProgram ap = new AnteckningsProgram();
                  ap.skapaVisaGUI();
    }

    The basic problem here is 'scope'. The scope of an attribute is 'Java 101' by the way. I recommend you start on the basics *(<- link)* and leave GUIs aside for a while.

  • Linking Editing TextArea with Button Handler

    Java newbie here,i am trying to create a program to display a keyboard on screen and display the the letter in a text area when the character letter is pressed. And the complete sentence when return is pressed.
    I have the GUI up, the problem is the letters are dispayed in a JOptionPane and i want them to be written to the TextArea.
    Any help would be appreaciated
    Here is the code in full so far.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    * Alphabet is a program that will display a text pad and 27 buttons of the 25
    * Letters of the Alphabet and display them when pressed and display all buttons
    * when Return button is pressed..
    * version (V 0.1)
    public class Alphabet extends JFrame
        private JPanel buttonPanel  ;
        private JButton buttons[];
        private JButton SpaceButton;
        private JButton ReturnButton;
        //setup GUI
        public Alphabet()
        super("Alphabet");
        //get content pane
        Container container = getContentPane();
        //create button array
        buttons = new JButton[122];
        //intialize buttons
        SpaceButton = new JButton ("Space");
        ReturnButton = new JButton ("Return");
        //setup panel and set its layout
        buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout (7,buttons.length));
        //create text area
        JTextArea TextArea = new JTextArea ();
       TextArea.setEditable(false);
       container.add(TextArea, BorderLayout.CENTER);
       // set a nice titled border around the TextArea
        TextArea.setBorder(
          BorderFactory.createTitledBorder("Your Text is Displayed Here"));
      //create and add buttons
        for (int count = 96; count <buttons.length; count++ ) {
        buttons[count] = new JButton( ""+ (char)(count +1 ));
        buttonPanel.add(buttons [count]);
        ButtonHandler handler = new ButtonHandler();
        buttons[count].addActionListener(handler);
        buttonPanel.add(SpaceButton);
       buttonPanel.add(ReturnButton);
       ReturnButton.setToolTipText( "Press to Display Sentence" ); 
         container.add(buttonPanel, BorderLayout.SOUTH);
        // set a nice titled border around the ButtonPanel
        buttonPanel.setBorder(
          BorderFactory.createTitledBorder("Click inside this Panel"));
            // create an instance of inner class ButtonHandler
              // to use for button event handling              
              ButtonHandler handler = new ButtonHandler(); 
              ReturnButton.addActionListener(handler);
            setSize (625,550);
            setVisible(true);
    }// end constructor Alphabet
    public static void main (String args[])
        Alphabet application = new Alphabet();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // inner class for button event handling
         private class ButtonHandler implements ActionListener {
              // handle button event
             public void actionPerformed( ActionEvent event )
                 JOptionPane.showMessageDialog( Alphabet.this,
                    "You pressed: " + event.getActionCommand() );
    }//END CLASS ALPHABET

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class Alphabet extends JFrame
    private JPanel buttonPanel ;
    private JButton buttons[];
    private JButton SpaceButton;
    private JButton ReturnButton;
    JTextArea TextArea;
    String str="";String stt="";
    //setup GUI
    public Alphabet()
    super("Alphabet");
    //get content pane
    Container container = getContentPane();
    //create button array
    buttons = new JButton[122];
    //intialize buttons
    SpaceButton = new JButton ("Space");
    ReturnButton = new JButton ("Return");
    //setup panel and set its layout
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout (7,buttons.length));
    //create text area
    TextArea = new JTextArea ();
    TextArea.setEditable(false);
    container.add(TextArea, BorderLayout.CENTER);
    // set a nice titled border around the TextArea
    TextArea.setBorder(
    BorderFactory.createTitledBorder("Your Text is Displayed Here"));
    //create and add buttons
    for (int count = 96; count <buttons.length; count++ ) {
    buttons[count] = new JButton( ""+ (char)(count +1 ));
    buttonPanel.add(buttons [count]);
    ButtonHandler handler = new ButtonHandler();
    buttons[count].addActionListener(handler);
    buttonPanel.add(SpaceButton);
    buttonPanel.add(ReturnButton);
    ReturnButton.setToolTipText( "Press to Display Sentence" );
    container.add(buttonPanel, BorderLayout.SOUTH);
    // set a nice titled border around the ButtonPanel
    buttonPanel.setBorder(
    BorderFactory.createTitledBorder("Click inside this Panel"));
    // create an instance of inner class ButtonHandler
    // to use for button event handling
    ButtonHandler handler = new ButtonHandler();
    ReturnButton.addActionListener(handler);
    SpaceButton.addActionListener(handler);
    setSize (625,550);
    setVisible(true);
    }// end constructor Alphabet
    public static void main (String args[])
    Alphabet application = new Alphabet();
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // inner class for button event handling
    private class ButtonHandler implements ActionListener {
    // handle button event
    public void actionPerformed( ActionEvent event )
              if((event.getActionCommand()).equals("Space")){
                   TextArea.setText(event.getActionCommand());
                   str+=" ";
                   //TextArea.append(" ");
              else if((event.getActionCommand()).equals("Return")){
                   stt+=str;
                   stt+="\n";
                   str="";
                   TextArea.setText(stt);
                   //TextArea.append(str);
                   //TextArea.append("\n");
              else {
                   TextArea.setText(event.getActionCommand());
                   str+=event.getActionCommand();
                   //TextArea.append(event.getActionCommand());
    }//END CLASS ALPHABET
    Ok?

  • Does TextArea support smooth focus navigation?

    Hi,
    I need to be notified when the user try to loose focus on a TextArea component, in order to ensure that the entered text by the user is valid. Same as the InputVerifier in swing
    I tried using setOnInputMethodTextChanged but It doesn't work. You can check the below example
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.TextArea;
    import javafx.scene.control.TextField;
    import javafx.scene.input.InputMethodEvent;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class JFXTextAreaExample extends Application {
        public JFXTextAreaExample() {
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage primaryStage) throws Exception {
            init(primaryStage);
            primaryStage.show();
        private void init(Stage primaryStage) {
            VBox root = new VBox();
            primaryStage.setScene(new Scene(root));
            TextField textField = new TextField("Text Field");
            TextArea textArea = new TextArea("Text Area");
            textArea.setOnInputMethodTextChanged(new EventHandler<InputMethodEvent>() {
                   @Override
                   public void handle(InputMethodEvent inputMethodEvent) {
                        System.out.println("Text changed");
            root.getChildren().add(0, textArea);
            root.getChildren().add(1, textField);
    }Thanks
    Edited by: 891575 on Dec 8, 2011 7:10 AM

    Thx for your answer
    I used focusedProperty.addListener(...) on my text area and it is working fine
    However I'm trying to use focusedProperty.addListener(...) on a HTML editor but it is not working.
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.geometry.Side;
    import javafx.scene.Scene;
    import javafx.scene.control.Tab;
    import javafx.scene.control.TabPane;
    import javafx.scene.control.TextArea;
    import javafx.scene.web.HTMLEditor;
    import javafx.stage.Stage;
    public class CustomHTMLEditor extends Application {
        private final String HTML = "<html><body>TEXT</body></html>";
        public CustomHTMLEditor() {
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage primaryStage) throws Exception {
            init(primaryStage);
            primaryStage.show();
        private void init(Stage primaryStage) {
            final HTMLEditor htmlEditor = new HTMLEditor();
            final TabPane tabPane = new TabPane();
            primaryStage.setScene(new Scene(tabPane));
            tabPane.setSide(Side.BOTTOM);
            Tab viewTab = new Tab();
            viewTab.setClosable(false);
            viewTab.setText("Renderer");
            viewTab.setContent(htmlEditor);
            tabPane.getTabs().add(0, viewTab);
            Tab htmlTab = new Tab();
            htmlTab.setClosable(false);
            htmlTab.setText("Editor");
            final TextArea textArea = new TextArea();
            textArea.onInputMethodTextChangedProperty();
            textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
                    @Override
                    public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                        if (!newValue) {
                            htmlEditor.setHtmlText(textArea.getText());
            htmlEditor.focusedProperty().addListener(new ChangeListener<Boolean>() {
                    @Override
                    public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                        if (!newValue) {
                            textArea.setText(htmlEditor.getHtmlText());
            htmlEditor.setHtmlText(HTML);
            textArea.setText(HTML);
            htmlTab.setContent(textArea);
            tabPane.getTabs().add(1, htmlTab);
    }Thanks
    Edited by: 891575 on Dec 8, 2011 7:11 AM

  • Trying to amend textArea

    I have a textArea(attached is a document listenter and a CaretListener) where I am trying to amend the contents. What I am trying to accomplish is when a user inputs text into the textArea that he/she cannot enter text past a certain point (ie caret postion 200). Also, if the text that gets inserted causes the text to go longer than caret position 200, then the text gets cut off.
    The problem is I get the following error when I try and replace or set the textArea.
    (java.lang.IllegalStateException: Attempt to mutate in notification)
    Yet I have another program where the same thing works fine in an actionListener. I do not understand why I can not get it to work in the document listener. The textArea gets locked for some reason and I can not ammend it. I f someone can help me that would be nice of you.
    java.lang.IllegalStateException: Attempt to mutate in notification
    public void setCursor()
    if(textArea.getCaretPosition() >= 200)
    textArea.setCaretPosition(200);
    public void delText()
    if(textArea.getText().length() > 200)
    String area = textArea.getText().substring(0, 199);
    textArea.setText(" ");
    textArea.replaceRange(area, 0 , 199); /* java.lang.IllegalStateException: Attempt to mutate in
    notification */
    class TextDocListener implements DocumentListener
    public void insertUpdate(DocumentEvent e) {delText();}
    public void removeUpdate(DocumentEvent e) {}
    public void changedUpdate(DocumentEvent e) {}
    class TextCaretListener implements CaretListener
    public void caretUpdate(CaretEvent e) { setCursor(); }

    Hi!
    Subclass javax.swing.text.PlainDocument
    then:
    public void insertString(int offset, String newString, javax.swing.text.AttributeSet set) throws javax.swing.text.BadLocationException
               String s = this.getContent()+newString;
               if(s.length()<200)
                       super.insertString(offset, newString, set);
                else
                   int cap = 200-this.getContent().length();
                   if(cap>0)
                          String ins = newString.subString(0, cap);
                          super.insertString(offset, ins, set);
    }Finally, when creating the TextArea call:
    myTextArea.setDocument(myPlainDocument);:)

  • Using TextArea to monitor query ...

    I am unable to do the following:
    Have a textarea and a button on a panel.
    When the button is clicked, the textarea displays "Starts Query"
    Then program queries the database.
    Finally, the textarea displays "end query".
    Problem: once the button is clicked, the textarea displays both
    "Start Query" and "End Query" AFTER the query is done. (I know this
    because the query is large - so at the very least I there should
    be a lapse of time between the two messages).
    There is a class that displays messages on the textarea (threaded)
    and there is a class for the query (threaded).
    the following is a snippet:
    void jButton1_actionPerformed(ActionEvent e) {
    String msg = "Start querying";
    Message m = new Message(textArea,msg);
    m.start();
    DBConnection db = new DBConnection();
    db.start();
    m.addMessage("Number of records:");
    in the run method of Message:
    public void run() {
    addMessage(msg);
    public synchronized void addMessage(String m) {
    t.append(m + "\n");
    and in the run method of the other class
    public void run() {
    doQuery();
    synchronized int doQuery() {
    int counter = 0;
    try {
    wait();
    rs = stmt.executeQuery(query);
    while (rs.next())
    counter ++;
    rs.close();
    stmt.close();
    con.close();
    return counter;
    catch (java.lang.InterruptedException ie) {}
    catch (SQLException sqlex) {}
    return -1;
    I am guessing that I am not using the threads the right way, or maybe I am
    totally off somewhere!
    Help is greatly appreciated!
    Thanks,
    Manyiu
    [email protected]

    After a quick look, it seems you are doing the right thing. The only suggestion i can give u is to get rid of the Message class (Is there a reason you need it?). Instead, do a textarea.settext before creating your db connection.

  • JTextArea.setText("String ") not updating the GUI.

    Hi,
    When i tried to update the JTextArea with a new String it is not replacing the string in the TextArea.
    If I try to print the content by retrieving the data in the TextArea using JTextArea.getText() it is showing the latest string set to the JTextArea.
    What might be the problem?
    DP

    Here is the code. I am calling the displayMessage() from onMessage() method.
    private void displayMessage(String str){
         textArea.setText(str);
         textArea.revalidate();
         System.out.println("Message Received from QUE: "+ textArea.getText());
    public void onMessage(Message msg) {
    try {
    if (msg instanceof TextMessage) {
         msgText = ((TextMessage)msg).getText();
    } else {
         msgText = msg.toString();
         msgText = msgText.trim();
    System.out.println(msgText );
    displayMessage(msgText);

  • Unable to clear a TextArea !!! .

    Folks,
    I am unable to clear a TextArea.
    I have defined a textArea which I need to clear.
    So I am saying:
    textArea.removeAll();
    but this is not clearng the TextArea at all.
    Am I missing something ? or is there something wrong??

    hello,
    textArea.setText("");regards
    tim

  • SetText doesn't work. A bug???

    I've got a JTextArea as a private atribute of my class:
    private JTextArea textArea = new JTextArea();
    And i've got a method that does:
    textArea.setText("blablabla");
    Well, the thing is, when i call that method... is doesn't do anything! I mean, the JTextArea remains with the same content. And the method is really being called (i'm sure 'cause i've done a System.out.print)
    And when i do textArea.append("blablabla") it doesn't work too!
    They only work when i call them from my class' constructor.
    Now, if that is not a bug, what is going on???
    Vic.

    THe problem is most likely that when you call this method, it is accessing a different instance of the object than the one in its constructor.
    Do you use more than one copy of this oject at a time? Consider the following
    private static JTextArea textArea = new JTextArea();and make the method static as well
    Hope this helps
    Guy

  • What could I possibly pass to setText() that could make it hang?

    I'm writing my own text editor called Bix. I've discovered that if I load a file whose path was taken in as a command line argument (as opposed to getting it with a JFileChooser), the function doOpen() hangs at setText(). This often--well, always--happens when the program is called from a different folder via a shortcut.
    The main function and the function doOpen are defined below:
    public static void main(String[] args){
            Bix thisBix = new Bix();
            thisBix.show();
            if (args.length > 0){
                File f = new File(args[0]);
                thisBix.doOpen(f);
    boolean doOpen(File f){
            boolean success = true;
            String fname = f.getName();
            String fpath = f.getPath();
            FileInputStream fis = null;
            String str = null;
            try {
                fis = new FileInputStream(f);
                int size = fis.available();
                byte[] bytes = new byte [size];
                fis.read(bytes);
                str = new String(bytes);
            } catch (IOException e) {
                success = false;
                JOptionPane.showMessageDialog(this,
                        "The file " + fname + " could not be read.\nReason: " + e.getMessage(),
                        "File Loading Problem", JOptionPane.ERROR_MESSAGE);
            } finally {
                try {
                    fis.close();
                } catch (IOException e2) {
                    System.err.println(e2);
            if (str != null){
                if (confirmReconditionFile(str)){
                    str = FileConditioner.conditionForEditing(str);
                } else {
                    translateEnabledBox.setSelected(false);
                    tabsAsSpacesRatio.setSelected(false);
                textArea.setText(str); //SOMETIMES SETTEXT HANGS HERE
                textArea.setCaretPosition(0);
                updateState(f);
                undo.discardAllEdits();
                previousFiles.push(f);
                return true;
            return false;
        }If I call System.out.println() with str just before I call setText(), the contents of the file are printed just fine.
    What gives?
    Any help would be appreciated...
    tim

    Probably you have troubles because you are trying to update your GUI outside of Swing event dispatching thread. Try to use SwingUtilites.invokeLater().
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

  • TextArea - Is it possible to get the number of lines?

    I was wondering if there's any way to know how many lines of text a textarea has. And also, if it'd be possible to listen for number of lines changes. I'm trying to develop a component which displays just one line at first, and then starts to grow as necessary, as the number of written lines increase.
    Let me know if it's not clear enough.
    Thanks in advance.

    Hi,
    May be what i am going to propose you is not the answer for your quesion. :P, but i have the same requirement and I achieved it in the following way. :)
    I wrapped by TextArea with a StackPane, and before adding the text area into the StackPane i added a Label, whose wrapText is set to true, and binded the prefWidth and text property with TextArea , as below.
    this.label =new Label();
    this.label.setWrapText(true);
    this.label.prefWidthProperty().bind(this.textArea.widthProperty());
    this.label.textProperty().bind(this.textArea.textProperty());That's it !!! It worked for me ;)
    Below is the complete code of this new customised control ;)
    ScrollFreeTextArea textArea= new ScrollFreeTextArea();And the complete class :
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    import javafx.scene.GroupBuilder;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.StackPane;
    import javafx.scene.layout.StackPaneBuilder;
    public class ScrollFreeTextArea extends StackPane{
         private Label label;
         private StackPane lblContainer ;
         private TextArea textArea;
         private Character NEW_LINE_CHAR = new Character((char)10);
         private final double NEW_LINE_HEIGHT = 18D;
         private final double TOP_PADDING = 3D;
         private final double BOTTOM_PADDING = 6D;
         public ScrollFreeTextArea(){
              super();
              configure();
         public ScrollFreeTextArea(String text){
              super();
              configure();
              textArea.setText(text);
         private void configure(){
              setAlignment(Pos.TOP_LEFT);
              this.textArea =new TextArea();
              this.textArea.setWrapText(true);
              this.textArea.getStyleClass().add("scroll-free-text-area");
              this.label =new Label();
              this.label.setWrapText(true);
              this.label.prefWidthProperty().bind(this.textArea.widthProperty());
              this.label.textProperty().bind(this.textArea.textProperty());
              this.lblContainer = StackPaneBuilder.create()
                                                        .alignment(Pos.TOP_LEFT)
                                                        .padding(new Insets(4,7,7,7))
                                                        .children(label)
                                                        .build();
              // Binding the container width to the TextArea width.
              lblContainer.maxWidthProperty().bind(textArea.widthProperty());
              textArea.textProperty().addListener(new ChangeListener<String>() {
                   @Override
                   public void changed(ObservableValue<? extends String> paramObservableValue,     String paramT1, String value) {
                        layoutForNewLine(textArea.getText());
              label.heightProperty().addListener(new ChangeListener<Number>() {
                   @Override
                   public void changed(ObservableValue<? extends Number> paramObservableValue,     Number paramT1, Number paramT2) {
                        layoutForNewLine(textArea.getText());
              getChildren().addAll(GroupBuilder.create().children(lblContainer).build(),textArea);
         private void layoutForNewLine(String text){
              if(text!=null && text.length()>0 &&
                             ((Character)text.charAt(text.length()-1)).equals(NEW_LINE_CHAR)){
                   textArea.setPrefHeight(label.getHeight() + NEW_LINE_HEIGHT + TOP_PADDING + BOTTOM_PADDING);
                   textArea.setMinHeight(label.getHeight() + NEW_LINE_HEIGHT + TOP_PADDING + BOTTOM_PADDING);
              }else{
                   textArea.setPrefHeight(label.getHeight() + TOP_PADDING + BOTTOM_PADDING);
                   textArea.setMinHeight(label.getHeight() + TOP_PADDING + BOTTOM_PADDING);
    }I hope you got the basic trick that I am doing here. I hope this can help you.
    Happy Coding :)
    Regards,
    Sai Pradeep Dandem.

  • How to call a method into setText() or append()       ?

    hello there
    i've made a JTextArea and i want to check the return of that method
    address.isReachable(3000); and print it on the TextArea
    how to do that?
    thanks

    thanks but it gives me an error cannot find simple
              final Timer timer = new Timer(2000, new ActionListener() {
                   public void actionPerformed(ActionEvent arg0) {
                        boolean b = address.isReachable(3000);
                    textArea.setText(String.valueOf(b));
              });in this line      boolean b = address.isReachable(3000);

  • BufferedReader or writer around a textarea

    Is there a way to wrap a bufferedReader or writer around a textarea?

    i would wait for an enter KeyEvent and then do the write then.
    public void keyPressed(KeyEvent e){
       if( e.getKeyCode == KeyEvent.VK_ENTER ){
           out.write( textArea.getText() );
           textArea.setText("");
    }

Maybe you are looking for

  • ITunes 10.6.3 installs correctly bot won't open or run

    I've tried installing, uninstalling and installing it again, but iTunes still won't run. I've tried installing previous versions until iTunes 10.5, but they won't run either. I've uninstalled bonjour too, but it still won't work, I've run a registry

  • Can't do video calls now

    See your family come together over a free group video call. Flase advertising as video calls are not working in the new 7.0.0.102. Settings are ok but the "Turn on video" button is greyed out. (Using Windows 7 Home Premium)

  • Insertion of Urdu Data in Oracle 8i

    Hello friends, I am working on an web-db application. I have to insert the records into Oracle 8i database in Urdu language. I am doing this using the J2EE architecture. Can someone please help me in this regard or send me a java piece of code in whi

  • Cost estimate and Dynamic Sourcing

    We have multiple levels of sourcing in R/3 and the cost estimate is using this info to determine the cost at a distribution center. The special procurement key is used in R/3. We are now in the process of implementing APO/SNP and dynamic sourcing wil

  • A way to find my previous questions and problem reports?

    Is there a way on this forum to find my previous questions and problem reports? Since posting a question earlier today, I've found MOST of the answer and would therefore like to append what I found to the question, without waiting for someone else to