How do you change the label text in java using eclipse and scene builder? -


i'm trying make "hello world" using eclipse , scene builder.

package lj.helloworld; import java.io.ioexception; import javafx.application.application; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.fxmlloader; import javafx.stage.stage; import javafx.scene.scene; import javafx.scene.control.label; import javafx.scene.layout.borderpane;  public class helloworld extends application {     private stage primarystage;     private borderpane rootlayout;  @override public void start(stage primarystage) {     this.primarystage = primarystage;     this.primarystage.settitle("addressapp");      initrootlayout(); }  /**  * initializes root layout.  */ public void initrootlayout() {     try {         // load root layout fxml file.         fxmlloader loader = new fxmlloader();         loader.setlocation(helloworld.class.getresource("roothelloworld.fxml"));         rootlayout = (borderpane) loader.load();          // show scene containing root layout.         scene scene = new scene(rootlayout);         primarystage.setscene(scene);         primarystage.show();     } catch (ioexception e) {         e.printstacktrace();     } } // attempt refer label object in scenebuilder. @fxml private label lbloutput;  @fxml private void handleclick(actionevent event) {     lbloutput.settext("this"); } } 

and fxml

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.borderpane?>  <borderpane prefheight="200.0" prefwidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">    <center>       <pane prefheight="200.0" prefwidth="200.0" borderpane.alignment="center">          <children>             <button fx:id="btnclick" layoutx="98.0" layouty="14.0" mnemonicparsing="false" text="click me" />             <label fx:id="lbloutput" layoutx="167.0" layouty="18.0" text="1231231" />          </children>       </pane>    </center> </borderpane> 

i want know how refer the label , change text "hello world". ps: i'm vb.net learning java. i've tried looking hello world sample on google sites down , others complicated me. ch.makery tutorial.

you need controller class

package lj.helloworld; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.scene.text.text;  public class fxmldocumentcontroller {  @fxml private label lbloutput;  @fxml protected void handlebuttonaction(actionevent e){ lbloutput.settext("hello world"); } } 

and tell xml controller class

 <borderpane  fx:controller="lj.helloworld.fxmldocumentcontroller"   <button fx:id="btnclick" layoutx="98.0" layouty="14.0" mnemonicparsing="false"    text="click me" onaction="#handlebuttonaction"/> 

for detailed information , tutorial pls read this: http://docs.oracle.com/javafx/2/get_started/hello_world.htm


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -