Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:30:44+00:00 2026-06-04T09:30:44+00:00

I am having problem in populating data from a table in one screen to

  • 0

I am having problem in populating data from a table in one screen to a Text Field in the other screen. I have two classes FirstClass containing a textbox and a button. On pressing a button a second window is opened containing a Table of values. As the user double clicks a row the value of the second column of the row should be inserted into the textbox of the FirstClass. Code of both the classes is attached. Thanking you in anticipation.

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class FirstClass extends Application {
public static void main(String[] args) {
    launch(args);
}

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("First Class");

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(5);
    gridpane.setVgap(5);

    final TextField userNameFld = new TextField();
    gridpane.add(userNameFld, 1, 1);
    Button btn = new Button();
    btn.setText("Show Table");
    gridpane.add(btn, 1, 3);

    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            String a = TableClass.showDialog(primaryStage, true, "Table Window" );
            userNameFld.setText(a);
        }
    });

    StackPane root = new StackPane();

    Scene scene =new Scene(root, 300, 250);

    root.getChildren().addAll(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
 }
}







import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class TableClass extends Stage {

private static TableClass dialog;
private static String value = "";


public static class Person {
    private final SimpleStringProperty firstName;
    private final SimpleStringProperty lastName;


    private Person(String fName, String lName) {
        this.firstName = new SimpleStringProperty(fName);
        this.lastName = new SimpleStringProperty(lName);
    }

    public String getFirstName() {
        return firstName.get();
    }
    public void setFirstName(String fName) {
        firstName.set(fName);
    }

    public String getLastName() {
        return lastName.get();
    }
    public void setLastName(String fName) {
        lastName.set(fName);
    }
}


 private TableView<Person> table = new TableView<Person>();
    private final ObservableList<Person> data = 
        FXCollections.observableArrayList(
            new Person("JACK", "BROWN"),
            new Person("JOHN", "VIANNEYS"),
            new Person("MICHAEL", "NELSON"),
            new Person("WILLIAM", " CAREY")
        );


public TableClass(Stage owner, boolean modality, String title) {
    super();
    initOwner(owner);
    Modality m = modality ? Modality.APPLICATION_MODAL : Modality.NONE;
    initModality(m);
    setOpacity(1);
    setTitle(title);

    StackPane root = new StackPane();

    Scene scene = new Scene(root, 750, 750);

    setScene(scene);
    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(5);
    gridpane.setVgap(5);


    TableColumn firstNameCol = new TableColumn("First Name");
    firstNameCol.setMinWidth(100);
    firstNameCol.setCellValueFactory(
    new PropertyValueFactory<Person,String>("firstName")
    );

    TableColumn lastNameCol = new TableColumn("Last Name");
    lastNameCol.setMinWidth(200);
    lastNameCol.setCellValueFactory(
    new PropertyValueFactory<Person,String>("lastName")
    );



    table.setItems(data);
    table.getColumns().addAll(firstNameCol, lastNameCol);



    table.setOnMouseClicked(new EventHandler<MouseEvent>() {

           public void handle(MouseEvent me) {

                   if (me.getClickCount() >= 2) {
                       String  srr = table.getItems().get    (table.getSelectionModel().getSelectedIndex()).getLastName();
                       value = srr;
                       dialog.hide();
                      }
               }
        });


    gridpane.add(table, 1, 5,1,20 );
    root.getChildren().add(gridpane);
    }


public static String showDialog(Stage stg, Boolean a , String title){
      dialog = new TableClass( stg,a, title);
      dialog.show();
      return value;
  }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:30:45+00:00Added an answer on June 4, 2026 at 9:30 am

    The quick and easy way (but it introduces coupling between the 2 classes) would be to pass userNameFld to your showDialog method and make it a member of TableClass. You can then change its value from the TableClass class.

    A better way would be to bind the value of userNameFld to value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of a problem with moving specific data from one server
I am having an issue populating a data table with the correct data. I
Having problem in displaying relational properties b/w two tables having one(company) to many(package_master) relationship
I'm having problem about web service method with auto increment ID. I have a
I'm having problem when running my Windows Forms program. In the program, I have
I'm using the jHTMLArea editor, and I'm having a problem with populating my textarea
I am having a problem in searching a ListView. In my activity I have
I'm having some trouble populating a dropdownlist with some JSON data, i suspect that
I am having trouble populating a datagridview with items from a string array. Here
I'm just getting started using ADO.NET and DataSets and DataTables. One problem I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.