I am trying to make a browser using javafx in which i want to add the bookmark functionality.I want to bookmark the webpage and display it in the menuitem.Bookmarking is working but the problem is that it is not displaying the bookmark field in the menuitem.I try to print the value in the console it is printing the value in the console but it is not displaying in the menuitem.
Now ,FirstpageController is the main controller whose fxml file is "Firstpage.fxml".This fxml only contain a tabpane.It contain an included file that is TabpageController which contains following code: TabpageController contains a button "bookmark_btn" which is used to add bookmark in the browser using addbookmark() method.It's fxml file is "Tabpage.fxml" which is included in "Firstpage.fxml".
TabpageController.java
public class TabpageController implements Initializable
{
@FXML public TextField addressField;
@FXML private Button bookmark_btn;
@FXML private Menu bookmenu;
@FXML public MenuItem bkmenuitem;
@FXML
private void addbookmark() throws IOException
{
Bookmodel bm = new Bookmodel(addressField.getText(), first.tab1.getText()); //Take the url and tile
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/tabcheck/Bookmarkpage.fxml"));
AnchorPane bookmarkpane = loader.load();
Stage bookstage = new Stage();
bookstage.setResizable(false);
bookstage.show();
Scene bookscene = new Scene(bookmarkpane);
bookstage.setScene(bookscene);
Bookmarkcontroller bc = loader.getController();
bc.setBookinfo(bm);
//bkmenuitem.setText(DEFAULT_HOME.toString());
}
public void setBookinfo(Bookmodel bookinfo)
{
System.out.println("setbookinfo enetring for add btn");
bkmenuitem.setText(bookinfo.getTitile());
System.out.println(bookinfo.getTitile());
System.out.println(bkmenuitem.getText());
System.out.println("setbookinfo");
this.bookinfo = bookinfo;
}
Now by clicking on "bookmark_btn" it open new scene that is "Bookmarkpage.fxml" which a simple bookmarking window which contain 2 textfield for url,title and "add" button.Now by clicking on "Add" button it should bookmark the current page.There is the menu "bookmenu" in the "tabpage.fxml" which contain menuitem "bkmenuitem".All the bookmark field should be display in the menuitem "bkmenuitem" which is in the "tabpage.fxml" file. Also the controller of this "Bookmarkpage.fxml" is "Bookmarkcontroller.java" which contain following code:
Bookmarkcontroller.java
public class Bookmarkcontroller {
@FXML
TextField bookmarkTitleTextField;
@FXML
TextField bookmarkURLTextField;
@FXML private Button addbook;
TabpageController tabpageController;
private Bookmodel bookinfo;
@FXML private void BookmarkToModelActionEvent(ActionEvent event) throws IOException
{
((Node) event.getSource()).getScene().getWindow().hide();
Bookmodel addbm = new Bookmodel(bookmarkTitleTextField.getText());
System.out.println(bookmarkTitleTextField.getText());
System.out.println("add to menuitems");
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/tabcheck/Tabpage.fxml"));
AnchorPane bookmarkpane = loader.load();
TabpageController addtc = loader.getController();
addtc.setBookinfo(addbm);
//bkmenuitem.setText(bookmarkTitleTextField.getText());
}
public void setBookinfo(Bookmodel bookinfo) {
bookmarkURLTextField.setText(bookinfo.getUrl());
bookmarkTitleTextField.setText(bookinfo.getTitile());
this.bookinfo = bookinfo;
}
This the model class of the "Bookmarkcontroller"
Bookmodel.java
public class Bookmodel {
private String url;
private String titile;
public Bookmodel() {
}
public Bookmodel(String url, String titile) {
this.url = url;
this.titile = titile;
}
public Bookmodel(String titile) {
this.titile = titile;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitile() {
return titile;
}
public void setTitile(String titile) {
this.titile = titile;
}
}
Output from Bookmarkcontroller.java
google
add to menuitems
Output from TabpageController.java
setbookinfo enetring for add btn
google
google
setbookinfo
As it is printing the output of these 2 lines as"google"
System.out.println(bookinfo.getTitile());
System.out.println(bkmenuitem.getText());
but not showing anything in the menuitem field for following line...
bkmenuitem.setText(bookinfo.getTitile());
I try a lot and also check it on stackoverflow on how to pass parameter from one controller to another but nothing is working.Also I am not getting any error.But the menuitem "bkmenuitem " is not printing the value.Any help would be appreciated as i am struggling a lot sorry for the long code .If i don't provide this much code then i won't understand anything.