Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX8 SceneBuilder自定义控件行为_Java_Netbeans_Javafx_Scenebuilder - Fatal编程技术网

JavaFX8 SceneBuilder自定义控件行为

JavaFX8 SceneBuilder自定义控件行为,java,netbeans,javafx,scenebuilder,Java,Netbeans,Javafx,Scenebuilder,我试图在JavaFX8中创建一个自定义控件。我想实现的是一个带有页眉和页脚的主播,每个页眉和页脚都可以包含控件。我注意到我在控件上创建的任何事件都不会在“设计模式”下触发。如何使用SceneBuilder将新节点拖放到控件中 下面是一个简单的例子。我有这个控制权 <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <?impor

我试图在JavaFX8中创建一个自定义控件。我想实现的是一个带有页眉和页脚的主播,每个页眉和页脚都可以包含控件。我注意到我在控件上创建的任何事件都不会在“设计模式”下触发。如何使用SceneBuilder将新节点拖放到控件中

下面是一个简单的例子。我有这个控制权

    <?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<fx:root minHeight="300" minWidth="300" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
        <AnchorPane fx:id="test" prefHeight="209.0" prefWidth="191.0">
           <children>
               <Button fx:id="button" layoutX="126" layoutY="90" onAction="#handleButtonAction" text="Click Me!" />    
               <Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
               <TextField fx:id="textField" layoutX="14.0" layoutY="14.0" />
               <HBox fx:id="hbox" layoutX="14.0" layoutY="40.0" prefHeight="100.0" prefWidth="100.0" style="-fx-background-color: RED;" />
           </children>  
        </AnchorPane>
    </children>
</fx:root>
在SceneBuilder 2.0中,如何实现在设计时将控件拖动到红色HBOX上

///*
// * To change this license header, choose License Headers in Project Properties.
// * To change this template file, choose Tools | Templates
// * and open the template in the editor.
// */
package javafxbeancontroltest;
//
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
//
///**
// *
// * @author ajmiro
// */

public class FXMLDocumentController extends AnchorPane
{    
    @FXML
    StringProperty labelText = new SimpleStringProperty("Initial Value");
    public String getLabelText() { return labelText.get(); }
    public void setLabelText(String newText) {labelText.set(newText);}
    public StringProperty labetTextProperty() { return labelText; }              

    public Button getButton() {return button;}  

    @FXML
    private AnchorPane test;    

    public AnchorPane getTest() {return test;}    

    @FXML
    private Label label;

    @FXML
    public Button button;

    @FXML
    private void handleButtonAction(ActionEvent event) {
        System.out.println("You clicked me!");
        //label.setText("Hello World!");
        label.setText(getLabelText());
        //label.setText(textField.getText());
    }



    public FXMLDocumentController() {            
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/javafxbeancontroltest/FXMLDocument.fxml"));
        fxmlLoader.setRoot(this);        
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (IOException ex) {
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        }                         
    }           
}