1

I am trying to use setPromptText on username

        TextField username = new TextField();
        username.setPromptText("enter your name");

I don't know why setPromptText is disabled. NetBeans shows a red underline on it and doesn't recognize this code and says

Cannot find symbol symbol: method setPromptText(String)

Is there anything that I'm missing? I have the related Swing libraries imported. Is there anything else spacial that I need to import?

Reza Taba
  • 1,151
  • 11
  • 15
  • The error tells you all you need to know: the method that you're calling doesn't exist. Java doesn't allow you to make up methods, and so you're forced to use methods that actually exist for that class. Perhaps here you meant to use `setText(...)`. The take-home lesson is: when you run into similar errors, look up and use only the methods that are allowed as per the [Java API](http://docs.oracle.com/javase/8/docs/api/index.html?overview-summary.html). – Hovercraft Full Of Eels Dec 20 '16 at 18:20

1 Answers1

0

Your problem is that TextField is not appart of swing. It is apart of the awt package. If you want access to the TextField you have to use JavaFx. Swing doesn't include a TextField. The only thing Swing has is JTextField, but that does not include a method called setPromptText(). Accept and +1 this answer if it fixed your issue :)

beastlyCoder
  • 2,349
  • 4
  • 25
  • 52