I have never tried to create a GUI and I am stuck on something that is probably not something that I should be stuck on. How do I get the text field to set the text without an action? I tried to use setText... I know I can have it set when I click the search button but I don't think it allows me to do that and append it to the query string. Any help or direction is very greatly appreciated.
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class gui extends Application {
Stage window;
ComboBox<String> dropDown;
Button button;
TextField searchString;
String dropField;
String inputText;
String queryText;
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Deep Search");
GridPane layout = new GridPane();
layout.setPadding(new Insets(10, 10, 10, 10));
layout.setVgap(8);
layout.setHgap(10);
//ComboBox Label
Label comboLabel = new Label("Field:");
GridPane.setConstraints(comboLabel, 0,0);
//ComboBox
dropDown = new ComboBox<>();
dropDown.getItems().addAll(
"all_fields",
"identifier",
"component",
"de_manager",
"de_priority",
"engineer",
"found",
"headline",
"integrated_releases_text",
"product",
"project",
"severity",
"status",
"submitted_on",
"submitter_id",
"version_text"
);
dropDown.setPromptText("Select Search Field");
dropDown.setOnAction( e -> setSearchField());
GridPane.setConstraints(dropDown, 2, 0);
//search box
searchString = new TextField();
searchString.setOnAction( e -> setSearchText());
searchString.setPromptText("Enter search string...");
GridPane.setConstraints(searchString, 2, 2);
Here is the text field. Here, the text is set when the user hits enter. I would like to know how I can set the text without an action as it is appended to a query with the choice that is made in the combo box above when the button is clicked.
//Search button
button = new Button("Search");
button.setOnAction( e -> queryMethod());
GridPane.setConstraints(button, 2, 10);
layout.getChildren().addAll(comboLabel, dropDown, searchString, button);
Scene scene = new Scene(layout, 300, 200);
window.setScene(scene);
window.show();
}
private void setSearchField(){
dropField = dropDown.getValue();
}
private void setSearchText(){
inputText = searchString.getText();
}
private void queryMethod(){
queryText = "SELECT identifier, component, de_manager, de_priority, engineer, found, headline, " +
"integrated_releases_text, product, project, severity, status, submitted_on, submitter_id, " +
"version_text FROM CDETS_ETL_BUG WHERE " + dropField + ":" + inputText;
}
}
