Anders Lund
Anders Lund

Reputation: 77

java.awt.TextField cannot be converted to javafx.scene.node

I get the error "incompatible types java.awt.TextField cannot be converted to javafx.scene.node" while I have imported the "javafx.scene.control.Label" which is what everyone on the internet tells to do.

import javafx.scene.control.Label;
import javafx.geometry.Insets;
import java.awt.*;
import java.applet.*;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane;
import javafx.geometry.Pos;
import javafx.scene.text.Text;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.HBox;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Font;




public class HelloWorlds extends Application {
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("JavaFX Welcome");

    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Text scenetitle = new Text("Welcome");
    scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(scenetitle, 0, 0, 2, 1);

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:");
    grid.add(pw, 0, 2);

    PasswordField pwBox = new PasswordField();
    grid.add(pwBox, 1, 2);

    Button btn = new Button("Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    final Text actiontarget = new Text();
    grid.add(actiontarget, 1, 6);

    Scene scene = new Scene(grid, 300, 275);
    primaryStage.setScene(scene);

    primaryStage.show();
}
}

Here is the code, its on grid.add(userTextField, 1, 1); this line that I get the error. Can anyone see what the issue is, and shortly explain it to me? :)

Upvotes: 2

Views: 7910

Answers (3)

m-h-makias
m-h-makias

Reputation: 1

you need to import javafx.scene.control.Button; and this needed to fix your problem

Upvotes: 0

Eric MONGO OVIENA
Eric MONGO OVIENA

Reputation: 1

you better use

import javafx.scene.control.Button;

Upvotes: 0

Gokul Nath KP
Gokul Nath KP

Reputation: 15553

Import from javafx.TextField.

Currently TextField is imported from awt.

Or in other words:

Remove import java.awt.*;.

Add import javafx.scene.control.TextField;.

Upvotes: 12

Related Questions