0 Replies - 891 Views - Last Post: 28 July 2019 - 06:22 PM Rate Topic: -----

#1 ik3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-May 19

Set web browser tab name after clicking enter

Posted 28 July 2019 - 06:22 PM

Hi, I'm working on a creating a web browser using JavaFX. I have a Main class which is responsible for creating new web browser tabs and then I have a Main Controller class that has a function that loads a web page when text is entered into a textbox and 'Enter' is pressed. Upon pressing enter, I would like the web browser's tab name to update accordingly.

  @FXML
    public void onEnter(ActionEvent ae) {
    	

        webaddressField.setonkeypressed(new EventHandler < KeyEvent > () {
            @Override
            public void handle(KeyEvent ke){
                //String url1;
                url1 = webaddressField.getText();

               if (ke.getCode().equals(KeyCode.ENTER)) {
                    //engine.load("https://" + url1);
				
                    if(!(url1.contains("https")))
                    {
                    	webaddressField.setText("https://" + url1);
                    	engine.load("https://" + url1);
                   		
                    	
                    }
                 
                    try {
						A.setTabNames(url1);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
                          
               }
               

            
        }});
       

    }


Per the code above, whatever the user enters will stored in String "url1". I was then trying to pass "url1" which contains the website url to a method in Main class called "setTabNames". My Main class however does not seem to be getting value. Any suggestions?


public void setTabNames(String tabName) throws IOException
    {
    	 String newTabName = tabName;
    	
    	 String aa= X.getURL();   //getUrl method in MainController class
         String html = aa;
         
         Document doc = Jsoup.parse(html);
         String s = doc.title();

         Scanner UrlScanner = new Scanner(html);
         while (UrlScanner.hasNextLine()) {
         String a = UrlScanner.nextLine().split(" ")[0]; 
         Document x = Jsoup.connect(a).get();
         String b= x.title();
         }
    }
    
    @Override
    public void start(Stage stage) {
        try {
            stage.setTitle("Av8 Web Browser");
            root = FXMLLoader.load(getClass().getResource("/avi8/Main.fxml"));
            //Scene scene = new Scene(root); 
            
           
            
            browserTab = new Tab(b,  root);


Is This A Good Question/Topic? 0
  • +

Page 1 of 1