我从来没有尝试过创建一个GUI而且我被困在一些可能不是我应该坚持的东西上。如何在没有操作的情况下获取文本字段来设置文本?我尝试使用setText ...我知道我可以在单击搜索按钮时设置它,但我认为它不允许我这样做并将其附加到查询字符串。非常感谢任何帮助或指导。
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);
这是文本字段。这里,当用户点击进入时设置文本。我想知道如何在没有操作的情况下设置文本,因为它会附加到查询中,并且单击按钮时会在上面的组合框中进行选择。
//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 BUG WHERE " + dropField + ":" + inputText;
}
}
答案 0 :(得分:0)
目前还不是很清楚你在问什么,但我想你只想从queryMethod()
的文本字段中获取文字:
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 + ":" + searchString.getText();
}