JavaFX Input from Buttons - java

I'm creating a simple ATM machine GUI using javaFX but I can't seem to know how to take an input from a button. For instance, I created a virtual number pad but I don't know how to take input from clicked buttons.
public static void displayNumbers() {
Stage window2 = new Stage();
GridPane grid = new GridPane();
window2.setTitle("Enter Value");
Button one = new Button("1");
Button two = new Button("2");
Button three = new Button("3");
Button four = new Button("4");
Button five = new Button("5");
Button six = new Button("6");
Button seven = new Button("7");
Button eight = new Button("8");
Button nine = new Button("9");
Button zero = new Button("0");
Button enterButton = new Button("Enter");
grid.add(one, 0, 0);
grid.add(two, 1, 0);
grid.add(three, 2, 0);
grid.add(four, 0, 1);
grid.add(five, 1, 1);
grid.add(six, 2, 1);
grid.add(seven, 0, 2);
grid.add(eight, 1, 2);
grid.add(nine, 2, 2);
grid.add(zero, 1, 3);
grid.add(enterButton, 2, 4);
}

To make a Button do something in JavaFX, you need to add an EventHandler. For example, let's tell button one to print something out to console:
one.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("You just clicked Button #1!");
}
});
This can be simplified with a lambda expression in JDK8+:
one.setOnAction(event -> System.out.println("You just clicked Button #1!"));
If you need to execute more than one line of code when clicking the button, just use a code block instead:
one.setOnAction(event -> {
// Do lots of things
});

Related

Why, Both radio buttons selected? i want single selection

I'm creating a radio question here I want select only one button to be selected. But here both buttons are got selected. kindly give me the solutions.
private void radioButtonQuestion(String radioquest, JsonArray optionsArray) {
RadioButton radio;
RadioGroup radioGroup;
JsonArray dependenciesArray = (JsonArray) indQuestions.get("dependencies");
ArrayList<String> list = new ArrayList<>();
for(int a=0; a<optionsArray.size();a++) {
JsonObject optionsObject = (JsonObject) optionsArray.get(a);
JsonObject dependenciesObject = (JsonObject) dependenciesArray.get(a);
String option = optionsObject.get("value").getAsString();
list.add(option);
}
LinearLayout ll=new LinearLayout(context);
ll.setOrientation(LinearLayout.VERTICAL);
cardview = new CardView(context);
layoutparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layoutparams.setMargins(10,20,10,20);
cardview.setLayoutParams(layoutparams);
cardview.setRadius(30);
cardview.setPadding(10, 10, 10, 10);
cardview.setCardBackgroundColor(Color.WHITE);
cardview.setMaxCardElevation(20);
cardview.setMaxCardElevation(6);
textview = new TextView(context);
// textview.setLayoutParams(layoutparams);
textview.setText(radioquest);
textview.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textview.setTextColor(Color.BLACK);
textview.setPadding(15, 25, 25, 15);
textview.setGravity(Gravity.NO_GRAVITY);
ll.addView(textview);
for(int i = 0; i< list.size();i++) {
radio = new RadioButton(context);
radioGroup = new RadioGroup(context);
radio.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
radio.setPadding(15, 15, 15, 15);
radio.setId(i);
radio.setText(list.get(i));
radioGroup.addView(radio);
ll.addView(radioGroup);
}
ll.setId(id);
cardview.addView(ll);
cardview.setId(id);
cardview.setTag("Radio "+id);
id++;
relativeLayout.addView(cardview);
}
Your code created a different group for each individual radio button, that's why each can be selected at the same time. Each group can have one selected radio button. Instead, you should create just one group, and add all the buttons to that group.
Just place radioGroup before options like below
radioGroup = new RadioGroup(context);
for(int i = 0; i< list.size();i++) {
radio = new RadioButton(context);
radio.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
radio.setPadding(15, 15, 15, 15);
radio.setId(i);
radio.setText(list.get(i));
radioGroup.addView(radio);
ll.addView(radioGroup);
}
From the reference from your code, I am able to find the cause which produces this issue, You need to put this line(ll.addView(radioGroup)) out of for loop as below :
//...
for(int i = 0; i< list.size();i++) {
radio = new RadioButton(context);
radioGroup = new RadioGroup(context);
radio.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
radio.setPadding(15, 15, 15, 15);
radio.setId(i);
radio.setText(list.get(i));
radioGroup.addView(radio);
}
ll.addView(radioGroup);
//...
If this solution helps then please accept this answer.

How can I add content from a helper method (including buttons, textfields, actions) to a tab created in a stage?

public void employeeMenu()
{
//ADD LOG OUT BUTTON SOMEWHERE
//setting stage
StackPane empMenuStage = new StackPane();
VBox empBox = new VBox(new Label("Employee Menu"));
empMenuStage.getChildren().add(empBox);
Scene empScene = new Scene(empMenuStage, 500, 500);
Stage empStage = new Stage();
empStage.setScene(empScene);
empStage.setTitle("Employee Menu");
TabPane tabPane = new TabPane();
Tab bookingReport = new Tab("Booking Report");
Tab checkOutGuest = new Tab("Check Out Guest");
Tab createGuestAccount = new Tab("Create Guest Account");
Tab editGuestInformation = new Tab("Edit Guest Info");
Tab createNewEmpAccount = new Tab("Create new Employee Account");
Tab editEmployeeAccount = new Tab("Edit Employee Account");
Tab editRoomStatus = new Tab("Edit Room Status");
tabPane.getTabs().add(bookingReport); //mitchell
tabPane.getTabs().add(checkOutGuest); //emma
tabPane.getTabs().add(createGuestAccount); //joey
tabPane.getTabs().add(editGuestInformation);
tabPane.getTabs().add(createNewEmpAccount);
tabPane.getTabs().add(editEmployeeAccount);
tabPane.getTabs().add(editRoomStatus);
VBox tabBox = new VBox(tabPane);
Scene scene = new Scene(tabBox, 500, 500);
empStage.setScene(scene);
empStage.setTitle("Employee Menu");
empStage.close();
empStage.show();
}
public Tab displayEmpMenu(Stage empStage)
{
//button for check out a value guest
//then enter name of value guest
//Enter room of value guest
//Confirmation Message (pick Y or N)
Tab test = new Tab("hi");
Button valueGuest = new Button("Check out Value Guest");
Button generalGuest = new Button("Check out General Guest");
valueGuest.setOnAction(e -> checkOutVG());
generalGuest.setOnAction(e -> checkOutGeneral());
GridPane layout = new GridPane();
layout.setPadding(new Insets(10, 10, 10, 10 ));
layout.setVgap(8);
GridPane.setConstraints(valueGuest, 0, 0);
GridPane.setConstraints(generalGuest,0, 1 );
layout.getChildren().addAll(valueGuest, generalGuest);
Scene scene = new Scene(layout, 650, 200 );
empStage.setScene(scene);
empStage.setTitle("Check Out Guest");
empStage.show();
//button for check out a general guest
//button for return to employee menu
return test;
}
public void checkOutVG()
{
TextField vgName = new TextField("Enter name of value guest");
String vgN = vgName.getText();
Label name = new Label("Value Guest Name");
TextField vgRoom = new TextField("Enter room of value guest");
Label roomNum = new Label("Value Guest Room");
double room = Double.parseDouble(vgRoom.getText());
int room1 = (int)room;
freeThisRoom(room1);
Label vgRoom1 = new Label("Value Guest Room");
TextField vgconfirm = new TextField("Confirmation: "
+ vgN + " is checking out of "
+ room1 + "(Y/N)");
vgconfirm.getText();
String text = "";
if (vgconfirm.getText().equalsIgnoreCase("Y"))
{
text = "Done. " + vgN + "is checked out of "
+ room1;
}
else
{
text = "You entered no. Please re-enter information.";
}
}
public void checkOutGeneral()
{
TextField name = new TextField("Enter name of general guest");
Label ggname = new Label("General Guest Name");
String name1 = name.getText();
TextField room = new TextField("Enter room number of general guest");
Label roomNum = new Label("General Guest Room");
double ggNum = Double.parseDouble(room.getText());
int ggRoom = (int)ggNum;
freeThisRoom(ggRoom);
TextField vgconfirm = new TextField("Confirmation: "
+ name + " is checking out of "
+ ggRoom + "(Y/N)");
vgconfirm.getText();
String text = "";
if (vgconfirm.getText().equalsIgnoreCase("Y"))
{
text = "Done. " + name + "is checked out of "
+ ggRoom;
}
else
{
text = "You entered no. Please re-enter information.";
}
}
I need help adding this content to the check out guest tab in the employee menu method. I'm new to javafx so if anyone could help me figure this out it would be greatly appreciated! I'm not sure what I am doing wrong or what I need to fix but I'm kind of lost. I've been scouring the web/textbooks for a solution but either I'm missing something big or I haven't come across the solution yet.

I can't click on the buttons

I'm making a sales system, and in the area where the total sums are described, I can't click on the buttons.
I tried to remove buttons from the gridpane and they work for me but when I integrate them into the gridpane they lose focus or stop working
Pane root = new Pane();
Separator top = new Separator(Orientation.HORIZONTAL);
top.setPrefWidth(1310);
Separator left = new Separator(Orientation.VERTICAL);
left.setPrefHeight(150);
left.setPadding(new Insets(0,0,10,0));
Separator low = new Separator(Orientation.HORIZONTAL);
low.setPadding(new Insets(140,10,0,0));
low.setPrefWidth(1323);
Separator right = new Separator(Orientation.VERTICAL);
right.setPrefHeight(150);
right.setPadding(new Insets(0,0,10,1310));
Label descuento = new Label("Descuento: ");
Label sub = new Label("Sub-Total: ");
Label iva = new Label("Iva: ");
Label total = new Label("Total: ");
Label rsub = new Label("0000.00");
Label riva= new Label("16%");
Label rtotal = new Label("0.0000");
Button btn_generate = new Button("generate");
MenuItem opc = new MenuItem("Opc");
MenuItem opc1= new MenuItem("opc1");
MenuButton menu1 = new MenuButton("Type",null,opc,opc1);
MenuItem opc2 = new MenuItem("opc2");
MenuItem opc3 = new MenuItem("opc3");
MenuButton menu2 = new MenuButton("Opc",null,opc2,opc3);
GridPane Gtotal = new GridPane();
Gtotal.setHgap(20);
Gtotal.setVgap(10);
Gtotal.setPadding(new Insets(10,0,0,10));
ColumnConstraints column1 = new ColumnConstraints(rtotal.getPrefWidth(),rtotal.getPrefWidth(),rtotal.getPrefWidth());
ColumnConstraints column2 = new ColumnConstraints(total.getPrefWidth()+450,total.getPrefWidth()+450,total.getPrefWidth()+450);
ColumnConstraints column3 = new ColumnConstraints(riva.getPrefWidth(),riva.getPrefWidth(),riva.getPrefWidth());
ColumnConstraints column4 = new ColumnConstraints(iva.getPrefWidth()+330,iva.getPrefWidth()+330,iva.getPrefWidth()+330);
ColumnConstraints column5 = new ColumnConstraints(rsub.getPrefWidth(),rsub.getPrefWidth(),rsub.getPrefWidth());
ColumnConstraints column6 = new ColumnConstraints(sub.getPrefWidth(),sub.getPrefWidth(),sub.getPrefWidth());
Gtotal.getColumnConstraints().add(0,column1);
Gtotal.getColumnConstraints().add(0,column2);
Gtotal.getColumnConstraints().add(0,column3);
Gtotal.getColumnConstraints().add(0,column4);
Gtotal.getColumnConstraints().add(0,column5);
Gtotal.getColumnConstraints().add(0,column6);
GridPane.setConstraints(descuento, 0, 0);
GridPane.setConstraints(menu1, 1, 0);
GridPane.setConstraints(menu2, 2, 0);
GridPane.setConstraints(sub, 0, 1);
GridPane.setConstraints(rsub, 1, 1);
GridPane.setConstraints(iva, 2, 1);
GridPane.setHalignment(iva, HPos.RIGHT);
GridPane.setConstraints(riva, 3, 1);
GridPane.setConstraints(total, 4, 1);
GridPane.setHalignment(total, HPos.RIGHT);
GridPane.setConstraints(rtotal, 5, 1);
GridPane.setConstraints(btn_generate, 5, 2);
Gtotal.getChildren().addAll(descuento,sub,rsub,iva,riva,total,rtotal,btn_generate,menu1,menu2);
root.getChildren().addAll(top,left,Gtotal,low,right);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
I hope that when running the program I can click on the buttons.
Marcos Antonio You are really making work for yourself not using Scene Builder
That said here is 3 lines of code that make a button fire an event
Button btnOK = new Button("OK");
btnOK.addEventHandler(ActionEvent.ACTION,filter);
btnOK.setOnAction((ActionEvent evt) -> {
The problem was the separators that overlapped the other layout by the padding

incompatible types: Scene cannot be converted to Parent JavaJDK netbeans

i have create a simple form with java jdk that contain a button, when user click the button it show the 2nd form and close the 1st form, but i have error like this in netbeans:
error: incompatible types: Scene cannot be converted to Parent
Scene secondScene = new Scene(scene2, 300,250);
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
now the full code of start :
public void start(Stage primaryStage) {
GridPane grid1 = new GridPane();
Button butt1 = new Button();
butt1.setText("Applique KPPV");
grid1.add(butt1, 2, 6);
Scene scene1 = new Scene(grid1, 300, 250);
primaryStage.setTitle("KNN With JDK");
primaryStage.setScene(scene1);
primaryStage.show();
butt1.setOnAction(e->{
GridPane grid = new GridPane();
// Labels & inputs Settings
Label number1 = new Label("Data 1 :");
Label number2 = new Label("Data 2 :");
Label number3 = new Label("Data 3 :");
Label number4 = new Label("Data 4 :");
Label number5 = new Label("Data 5 :");
Label numberk = new Label("K :");
Label resultat1 = new Label("The Result");
TextField txt1 = new TextField();
TextField txt2 = new TextField();
TextField txt3 = new TextField();
TextField txt4 = new TextField();
TextField txt5 = new TextField();
TextField txtk = new TextField();
grid.add(number1, 0, 0);
grid.add(number2, 0, 1);
grid.add(number3, 0, 2);
grid.add(number4, 0, 3);
grid.add(number5, 0, 4);
grid.add(numberk, 0, 5);
grid.add(resultat1, 0, 7);
grid.add(txt1, 1, 0);
grid.add(txt2, 1, 1);
grid.add(txt3, 1, 2);
grid.add(txt4, 1, 3);
grid.add(txt5, 1, 4);
grid.add(txtk, 1, 5);
Button butt = new Button();
butt.setText("Applique KPPV");
grid.add(butt, 0, 6);
// My Main Method
///////////////////////////////////
// ADDED THESE 5 LINES. NOW IT SHOWS A WINDOW WITH THESE VALUES FILLED IN
txt1.setText("0.0");
txt2.setText("0.0");
txt3.setText("0.0");
txt4.setText("0.0");
txt5.setText("0.0");
txtk.setText("10");
double insertedInt = Double.parseDouble(txt1.getText());
double insertedInt2 = Double.parseDouble(txt2.getText());
double insertedInt3 = Double.parseDouble(txt3.getText());
double insertedInt4 = Double.parseDouble(txt4.getText());
double insertedInt5 = Double.parseDouble(txt5.getText());
///////////////////////////////////
Scene scene = new Scene(grid, 300, 250);
// Final Action
butt.setOnAction(event -> {
double[] query = { insertedInt, insertedInt2, insertedInt3, insertedInt4, insertedInt5 };
int k = Integer.parseInt(txtk.getText());
List<City> cityList = new ArrayList<City>();
List<Result> resultList = new ArrayList<Result>();
cityList.add(new City(instances[0], "IRIS0"));
cityList.add(new City(instances[1], "IRIS1"));
cityList.add(new City(instances[2], "IRIS2"));
cityList.add(new City(instances[3], "IRIS3"));
cityList.add(new City(instances[4], "IRIS4"));
cityList.add(new City(instances[5], "IRIS5"));
cityList.add(new City(instances[6], "IRIS6"));
cityList.add(new City(instances[7], "IRIS7"));
cityList.add(new City(instances[8], "IRIS8"));
cityList.add(new City(instances[9], "IRIS9"));
// find distances
for (City city : cityList) {
double dist = 0.0;
for (int j = 0; j < city.cityAttributes.length; j++) {
dist += Math.pow(city.cityAttributes[j] - query[j], 2);
}
double distance = Math.sqrt(dist);
resultList.add(new Result(distance, city.cityName));
}
Collections.sort(resultList, new DistanceComparator());
String[] ss = new String[k];
for (int x = 0; x < k; x++) {
ss[x] = resultList.get(x).cityName;
}
String majClass = findMajorityClass(ss);
// System.out.println("The Nearest IRIS Class is : "+majClass);
resultat1.setText(majClass);
});
Scene secondScene = new Scene(scene, 500,500);
Stage secondStage = new Stage();
secondStage.setScene(secondScene); // set the scene
secondStage.setTitle("Second Form");
secondStage.show();
primaryStage.close(); // close the first stage (Window)
});
}

How to make Javafx remember form values?

What I need is for a user to be able to click any tag on a web page. Once they click the tag a new button appears in a GridPane. When I click the new button in the GridPane a small dialog box appears with all the attributes that exist in the tag.
Step by step:
I load google.com
I click the link at the foot "About"
A button appears in the GridPane
I click the button that just appeared
A smaller window appears that lists:
About
xpath: id("fsl")/A[3] //this is a the xpath of the click which I use js
class: _Gs
href: //www.google.com/intl/en/about.html?fg=1
Then I close this smaller window and click Business
A new button appears in the gridpane
I click the button that just appeared
A smaller window appears with new list of attributes:
Business
xpath: id("fsl")/A[2]
class: _Gs
href: //www.google.com/services/?fg=1
That's the idea.
The issue is when I click Business, the xpath of About is replaced with the xpath for Business. When I open the content of About in the gridpane everything is still the same except xpath is now id("fsl")/A[2] instead of id("fsl")/A[3]
It all starts in the worker
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>(){
public void changed(ObservableValue ov, State oldState, State newState){
if(newState == javafx.concurrent.Worker.State.SUCCEEDED){
//attach listener to all tags "*"
EventListener listener = new EventListener(){
public void handleEvent(org.w3c.dom.events.Event evt) {
addNewInstruction(evt);
setXPath();
}
};
setListenerByTagNames(listener, "a");
}
}
});
//xpath method
private void setXPath(){
JSObject hrefWindow = (JSObject) engine.executeScript("window");
hrefWindow.setMember("java", bridge);
engine.executeScript("var links = document.getElementsByTagName(\"*\");"+
"for (var i = 0; i < links.length; i++) {"+
"links[i].addEventListener(\"click\", function(){"+
"document.onclick = function(event) {" +
"if (event===undefined) event= window.event;" +
"var target= 'target' in event? event.target : event.srcElement; " +
"var root= document.compatMode==='CSS1Compat'? document.documentElement : document.body;" +
"var mxy= [event.clientX+root.scrollLeft, event.clientY+root.scrollTop];" +
"var path= getPathTo(target);" +
"var txy= getPageXY(target);" +
"java.log(path);" +
"}" +
"});"+
"}"+
"function getPathTo(element) {" +
"if (element.id!=='')" +
"return 'id(\"'+element.id+'\")';" +
"if (element===document.body)" +
"return element.tagName;" +
"var ix= 0;" +
"var siblings= element.parentNode.childNodes;" +
"for (var i= 0; i<siblings.length; i++) {" +
"var sibling= siblings[i];" +
"if (sibling===element)" +
"return getPathTo(element.parentNode)+'/'+element.tagName+'['+(ix+1)+']';" +
"if (sibling.nodeType===1 && sibling.tagName===element.tagName)" +
"ix++;" +
"}" +
"}" +
"function getPageXY(element) {" +
"var x= 0, y= 0;" +
"while (element) {" +
"x+= element.offsetLeft;" +
"y+= element.offsetTop;" +
"element= element.offsetParent;" +
"}" +
"return [x, y];" +
"}");
}
The javabridge class
public class JavaBridge extends Amz
{
public String text = "EMPTY STRING";
public void log(String text){
this.text = text;
}
}
The instruction method
private void addNewInstruction(org.w3c.dom.events.Event evt){
String htmlTagName = ((Element)evt.getTarget()).getTagName();
if(instructionIncrementCol == 10){
instructionIncrementRow++;
instructionIncrementCol= 0;
}
final Button button = new Button(htmlTagName);
button.setOnAction(
new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
//Grid Specs
GridPane primaryGrid = new GridPane();
Element element = ((Element)evt.getTarget());
primaryGrid.setVgap(4);
primaryGrid.setPadding(new Insets(5, 5, 5, 5));
TitledPane titleSlider = new TitledPane();
titleSlider.setText("Instructions");
titleSlider.setContent(primaryGrid);
titleSlider.setContent(primaryGrid);
final GridPane secondGrid = new GridPane();
secondGrid.setVgap(4);
secondGrid.setPadding(new Insets(20));
secondGrid.setPrefHeight(100);
ScrollPane sp = new ScrollPane(secondGrid);
sp.setHbarPolicy(ScrollBarPolicy.ALWAYS);
sp.setMaxHeight(400);
primaryGrid.add(sp, 0, 1);
GridPane.setHgrow(sp, Priority.ALWAYS);
GridPane.setVgrow(sp, Priority.ALWAYS);
//Form
int rowOnePos = 0;
int rowTwoPos = 1;
int rowThreePos = 2;
int loopRowPos = 3;
String tagType = element.getTagName();
if(tagType.equals("INPUT")){
createInputInstructionObject(secondGrid,rowOnePos, element);
}else{
Button click = new Button("Click");
secondGrid.add(click, 0, rowOnePos);
click.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent e){
sql.insertRow("click", element.getAttribute("href"));
//writeToFile("click,"+((Element)evt.getTarget()).getAttribute("href"));
}
});
Text textLabel = new Text("Text");
TextField textContentValue = new TextField(element.getTextContent());
Button grabDataText = new Button("Grab");
textContentValue.setPrefWidth(300);
secondGrid.add(textLabel, 0, rowTwoPos);
secondGrid.add(textContentValue, 1, rowTwoPos);
secondGrid.add(grabDataText, 2, rowTwoPos);
textContentValue.setPrefWidth(300);
}
//xpath
Text xpathLabel = new Text("XPath");
final String stay = bridge.text+" ";
TextField xpathValue = new TextField(stay);
Button grabDataxpath = new Button("Grab");
secondGrid.add(xpathLabel, 0, rowThreePos);
secondGrid.add(xpathValue, 1, rowThreePos);
secondGrid.add(grabDataxpath, 2, rowThreePos);
//all attributes for this tag
NamedNodeMap attributes = element.getAttributes();
for(int i = 0; i < attributes.getLength(); i++){
//create row for each attribute
createInstructionObject(attributes, i, secondGrid, loopRowPos);
}
final Stage dialog = new Stage();
Scene dialogScene = new Scene(primaryGrid, 500, 500);
dialog.setScene(dialogScene);
dialog.show();
}
});
instructionSecondaryGrid.add(button,instructionIncrementCol,instructionIncrementRow);
instructionIncrementCol++;
}
Your code isn't very understandable - lots of references are declared and not used, or not declared and then referred to (the latter means it won't compile) - but as far as I can understand it you just need to create the dialog once for each button, instead of recreating it every time the button is pressed:
private void addNewPane(org.w3c.dom.events.Event evt){
final Button button = new Button(htmlTagName);
final Stage dialog = new Stage();
GridPane primaryGrid = new GridPane();
Element element = ((Element)evt.getTarget());
primaryGrid.setVgap(4);
primaryGrid.setPadding(new Insets(5, 5, 5, 5));
TitledPane gridTitlePane = new TitledPane();
GridPane secondGrid = new GridPane();
secondGrid.setVgap(4);
secondGrid.setPadding(new Insets(20));
secondGrid.setPrefHeight(100);
ScrollPane sp = new ScrollPane(secondGrid);
sp.setHbarPolicy(ScrollBarPolicy.ALWAYS);
sp.setMaxHeight(400);
int rowThreePos = 2;
//text content of data
secondGrid.add(new Text("XPath"), 0, rowThreePos);
secondGrid.add(new TextField(holdXPath), 1, rowThreePos);
secondGrid.add(new Button("Grab"), 2, rowThreePos);
primaryGrid.add(sp, 0, 1);
GridPane.setHgrow(sp, Priority.ALWAYS);
GridPane.setVgrow(sp, Priority.ALWAYS);
gridTitlePane.setText("Forms");
gridTitlePane.setContent(primaryGrid);
gridTitlePane.setContent(primaryGrid);
Scene dialogScene = new Scene(primaryGrid, 500, 500);
dialog.setScene(dialogScene);
button.setOnAction(
new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
dialog.show();
}
});
SecondaryGrid.add(button,IncrementCol,IncrementRow);
IncrementCol++;
}
Finally found a solution. I ended up using javascript to insert the XPath into SQLite DB, upon loading page, and assigning a new attribute to the tag with the ID of the XPath in the DB.
like so:
Click Me
//the JS
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
java.insertIntoDB(getXPathID(anchors[i]));
anchors[i].setAttribute("mycustomAttr", java.getMaxId());
}

Categories