0

I'm attempting to create a simple text editor in JavaFX but have stumbled upon a problem. My code that is supposed to save the current text can't get that text from the TextArea in my Scene. When I call getText() on the TextArea I just get back an empty string, even though something is written in there.

The TextArea is created in my Main class and assigned to a static field of a small helper-class called Global, so that it can be accessed in my other class ApplicationMenu where I call getText().

Check out my source code at https://github.com/axelkennedal/Kode

Notes:

  • getText()works as expected from inside my Main class
  • I tested using a TextArea directly without encapsulating it in TextEditor and this works as expected when calling getText() on it from ApplicationMenu
theB
  • 6,450
  • 1
  • 28
  • 38
Kennedal
  • 23
  • 7

1 Answers1

0

Solved the problem by changing my implementation of TextEditor to this:

public class TextEditor extends TextArea
{

    TextEditor()
    {
        super();
    }

    public void printText()
    {
        System.out.println(getText());
    }
}
Kennedal
  • 23
  • 7