当前位置: 首页 > 知识库问答 >
问题:

是否可以将包含自定义JavaFX控件的JAR导入到场景生成器中?

晋俊贤
2023-03-14

当我在一个舞台上工作时,我注意到我几乎有三次完全相同的东西。而不是那样(因为我讨厌那样),我决定把我有的3次,并把它变成一个自定义组件。

现在我知道我可以在代码中添加它,但我不能预测布局行为(其中两个将直接进入选项卡,第三个将进入网格窗格)。

<DGCSDefiner //other layout related XML code/>

我不想要的是:

<GridPane //bla bla XML layout code>
    <columnConstraints>
      //bla bla column constraint stuff
    </columnConstraints>
    //etc, etc
</GridPane>

这可能吗?我又从C#和VS2010中出来了,当涉及到自定义控件时,我有点被宠坏了,所以如果有可能让类似的事情发生,有人能告诉我怎么做吗?

是否可以将包含自定义JavaFX控件的编译好的JAR文件导入到Scene Builder中,以便将其从库中放入会产生我在上面描述的结果?

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

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

<fx:root alignment="CENTER" hgap="5.0" styleClass="root" stylesheets="@DGCSDefiner.css" type="GridPane" vgap="5.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="DGCSDefiner.DGCSDefinerController">
   <children>
      <ComboBox fx:id="cbxColorStyle" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="150.0" promptText="Select Background Color Style" />
      <ColorPicker fx:id="cpSolidColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="32.0" prefWidth="283.0" visible="false" GridPane.rowIndex="1" />
      <StackPane fx:id="spSettings" styleClass="Group" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
         <children>
            <GridPane fx:id="gpLinearSettings" hgap="5.0" styleClass="Group" vgap="20.0" visible="false">
               <children>
                  <Label text="Angle" GridPane.halignment="RIGHT" GridPane.valignment="CENTER">
                     <font>
                        <Font name="Arial" size="12.0" />
                     </font>
                  </Label>
                  <ComboBox fx:id="cbxLinearAngle" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="150.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
                  <Label text="1st Color" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />
                  <ColorPicker fx:id="cpFirstLinearColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
                  <Label text="2nd Color" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
                  <ColorPicker fx:id="cpSecondLinearColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS" />
               </children>
               <columnConstraints>
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
               </columnConstraints>
               <rowConstraints>
                  <RowConstraints minHeight="10.0" vgrow="NEVER" />
                  <RowConstraints minHeight="10.0" vgrow="NEVER" />
                  <RowConstraints minHeight="10.0" vgrow="NEVER" />
               </rowConstraints>
            </GridPane>
            <TabPane fx:id="tabRadialSettings" styleClass="Group" tabClosingPolicy="UNAVAILABLE" visible="false">
               <tabs>
                  <Tab closable="false" text="Colors">
                     <content>
                        <GridPane hgap="5.0" styleClass="Group" vgap="5.0">
                           <children>
                              <Label maxHeight="1.7976931348623157E308" text="1st Color" GridPane.vgrow="NEVER" />
                              <ColorPicker fx:id="cpFirstRadialColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.vgrow="NEVER" />
                              <Label maxHeight="1.7976931348623157E308" text="2nd Color" GridPane.rowIndex="1" GridPane.vgrow="NEVER" />
                              <ColorPicker fx:id="cpSecondRadialColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.vgrow="NEVER" />
                           </children>
                           <columnConstraints>
                              <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
                              <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                           </columnConstraints>
                           <rowConstraints>
                              <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                              <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                           </rowConstraints>
                        </GridPane>
                     </content>
                  </Tab>
                  <Tab closable="false" text="Size and Position">
                     <content>
                        <GridPane hgap="5.0" styleClass="Group" vgap="5.0">
                           <children>
                              <Label text="H Position" />
                              <Label text="V Position" GridPane.rowIndex="1" />
                              <Label text="Radius" GridPane.rowIndex="2" />
                              <Slider fx:id="sliderHPos" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="1.0" showTickMarks="true" GridPane.columnIndex="1" />
                              <Slider fx:id="sliderVPos" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="1.0" showTickMarks="true" value="1.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                              <Slider fx:id="sliderRadius" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="1.0" showTickMarks="true" value="1.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                           </children>
                           <columnConstraints>
                              <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
                              <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                           </columnConstraints>
                           <rowConstraints>
                              <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                              <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                              <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                           </rowConstraints>
                        </GridPane>
                     </content>
                  </Tab>
               </tabs>
            </TabPane>
         </children>
      </StackPane>
   </children>
   <columnConstraints>
      <ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
      <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
      <RowConstraints minHeight="10.0" vgrow="ALWAYS" />
   </rowConstraints>
</fx:root>
package DGCSDefiner;

import java.io.IOException;
import static java.util.Arrays.asList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.control.TabPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;

public class DGCSDefiner extends Pane { //DigiGames Color Settings Definer.
    // Values injected by FXMLLoader
    //<editor-fold defaultstate="collapsed" desc="FXML Variables">
    //<editor-fold defaultstate="collapsed" desc="Containers">
    @FXML private GridPane  gpLinearSettings;   // fx:id="gpLinearSettings"
    @FXML private StackPane spSettings;         // fx:id="spSettings"
    @FXML private TabPane   tabsRadialSettings; // fx:id="tabRadialSettings"
    //</editor-fold>
        //<editor-fold defaultstate="collapsed" desc="Color Pickers">
    @FXML private ColorPicker cpSolidColor,         // fx:id="cpSolidColor"
                              cpFirstLinearColor,   // fx:id="cpFirstLinearColor"
                              cpSecondLinearColor,  // fx:id="cpSecondLinearColor"
                              cpFirstRadialColor,   // fx:id="cpFirstRadialColor"
                              cpSecondRadialColor;  // fx:id="cpSecondRadialColor"
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Combo Boxes">
    @FXML private ComboBox<ColorStyles>     cbxColorStyle;  // fx:id="cbxColorStyle"
    @FXML private ComboBox<Integer>     cbxLinearAngle; // fx:id="cbxLinearAngle"
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Sliders">
    @FXMLprivate Slider     sliderRadius,   // fx:id="sliderRadius"
                            sliderHPos,     // fx:id="sliderHPos"
                            sliderVPos;     // fx:id="sliderVPos"
    //</editor-fold>
    //</editor-fold>
    private FXMLLoader Loader;

    @FXML // This method is called by the FXMLLoader when initialization is complete
    void initialize() {
        //<editor-fold defaultstate="collapsed" desc="Assertions">
        //<editor-fold defaultstate="collapsed" desc="Container Assertions">
        assert this.gpLinearSettings    != null : "fx:id=\"gpLinearSettings\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.spSettings      != null : "fx:id=\"spSettings\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.tabsRadialSettings  != null : "fx:id=\"tabsRadialSettings\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fhtml" target="_blank">xml'.";
        //</editor-fold>
        //<editor-fold defaultstate="collapsed" desc="ColorPicker Assertions">
        assert this.cpSolidColor    != null : "fx:id=\"cpSolidColor\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.cpFirstLinearColor  != null : "fx:id=\"cpFirstLinearColor\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.cpSecondLinearColor != null : "fx:id=\"cpSecondLinearColor\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.cpFirstRadialColor  != null : "fx:id=\"cpFirstRadialColor\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.cpSecondRadialColor != null : "fx:id=\"cpSecondRadialColor\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        //</editor-fold>
        //<editor-fold defaultstate="collapsed" desc="ComboBox Assertions">
        assert this.cbxColorStyle   != null : "fx:id=\"cbxColorStyle\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.cbxLinearAngle  != null : "fx:id=\"cbxLinearAngle\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        //</editor-fold>
        //<editor-fold defaultstate="collapsed" desc="Slider Assertions">
        assert this.sliderRadius    != null : "fx:id=\"sliderRadius\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.sliderHPos      != null : "fx:id=\"sliderHPos\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        assert this.sliderVPos      != null : "fx:id=\"sliderVPos\" was not injected: check your FXML file 'JFXMLColorStyleDefiner.fxml'.";
        //</editor-fold>
        //</editor-fold>
        //<editor-fold defaultstate="collapsed" desc="Initializations">
        //<editor-fold defaultstate="collapsed" desc="ComboBox Initializations">
        this.cbxColorStyle.getItems().addAll(
            asList(ColorStyles.values())
        );
        for (int x = 0; x < 8; x++)
            this.cbxLinearAngle.getItems().add(x * 45);
        this.cbxColorStyle.setOnAction(event -> {
            ColorStyles CS = this.cbxColorStyle.getValue();
            this.cpSolidColor.setVisible(CS == ColorStyles.SOLID);
            this.gpLinearSettings.setVisible(CS == ColorStyles.LINEAR);
            this.tabsRadialSettings.setVisible(CS == ColorStyles.RADIAL);
        });
        //</editor-fold>
        this.Loader = new FXMLLoader(
            this.getClass().getResource("DGCSDefiner.fxml")
        );
        this.Loader.setRoot(this);
        this.Loader.setController(this);
        //</editor-fold>
    }

    public DGCSDefiner(){
        try{ this.Loader.load(); }
        catch(IOException e){ throw new RuntimeException(e); }
    }

    /**
     * Get the ColorSettings defined by the control.
     * @return Defined Color Settings.
     */
    public ColorSettings getColorSettings(){
        if (this.cbxColorStyle.getSelectionModel().getSelectedIndex() < 0)
            return null;
        switch(this.cbxColorStyle.getValue()){
            case SOLID:
                return new ColorSettings(this.cpSolidColor.getValue());
            case LINEAR:
                return new ColorSettings(
                    this.cpFirstLinearColor.getValue(),
                    this.cpSecondLinearColor.getValue(),
                    this.cbxLinearAngle.getValue()
                );
            case RADIAL:
                return new ColorSettings(
                    this.cpFirstRadialColor.getValue(),
                    this.cpSecondRadialColor.getValue(),
                    (int)this.sliderRadius.getValue(),
                    (int)this.sliderHPos.getValue(),
                    (int)this.sliderVPos.getValue()
                );
        }
        return null; //This should never happen.
    }
    /** 
     * Load defined color settings.
     * @param cs Predefined color settings.
     */
    public void setColorSettings(ColorSettings cs){
        this.cbxColorStyle.setValue(cs.Style);
        switch(cs.Style){
            case SOLID:
                this.cpSolidColor.setValue(cs.clrPrimary);
                break;
            case LINEAR:
                this.cbxLinearAngle.setValue(cs.intAngle);
                this.cpFirstLinearColor.setValue(cs.clrPrimary);
                this.cpSecondLinearColor.setValue(cs.clrSecondary);
                break;
            case RADIAL:
                this.sliderRadius.setValue(cs.intSize);
                this.sliderHPos.setValue(cs.intHPos);
                this.sliderVPos.setValue(cs.intVPos);
                this.cpFirstRadialColor.setValue(cs.clrPrimary);
                this.cpSecondRadialColor.setValue(cs.clrSecondary);
        }
    }
}
/*
 * 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 DGCSDefiner;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;

/**
 *
 * @author Will
 */
public class DGCSDefinerController implements Initializable {
    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}

编辑2好。我有预感,事实证明是正确的,但没有帮助。我删除了控件CSS样式表引用,它允许我添加控件,没有问题。

然而,当我把它放在FXML文件中时,这就是发生在FXML文件中的情况:

它来自以下内容(仅显示相关部分):

<Tab fx:id="tabBGStyle" closable="false" text="Background" />
<Tab fx:id="tabBGStyle" closable="false" text="Background">
    <content>
        <GridPane alignment="CENTER" hgap="5.0" styleClass="root" vgap="5.0">
            <children>
                <ComboBox fx:id="cbxColorStyle" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="150.0" promptText="Select Background Color Style" />
                <ColorPicker fx:id="cpSolidColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="32.0" prefWidth="283.0" visible="false" GridPane.rowIndex="1" />
                <StackPane fx:id="spSettings" styleClass="Group" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
                    <children>
                        <GridPane fx:id="gpLinearSettings" hgap="5.0" styleClass="Group" vgap="20.0" visible="false">
                            <children>
                                <Label text="Angle" GridPane.halignment="RIGHT" GridPane.valignment="CENTER">
                                    <font>
                                        <Font name="Arial" size="12.0" />
                                    </font>
                                </Label>
                                <ComboBox fx:id="cbxLinearAngle" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="150.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
                                <Label text="1st Color" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />
                                <ColorPicker fx:id="cpFirstLinearColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
                                <Label text="2nd Color" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
                                <ColorPicker fx:id="cpSecondLinearColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS" />
                            </children>
                            <columnConstraints>
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                            </columnConstraints>
                            <rowConstraints>
                                <RowConstraints minHeight="10.0" vgrow="NEVER" />
                                <RowConstraints minHeight="10.0" vgrow="NEVER" />
                                <RowConstraints minHeight="10.0" vgrow="NEVER" />
                            </rowConstraints>
                        </GridPane>
                        <TabPane fx:id="tabRadialSettings" styleClass="Group" tabClosingPolicy="UNAVAILABLE" visible="false">
                            <tabs>
                                <Tab closable="false" text="Colors">
                                    <content>
                                        <GridPane hgap="5.0" styleClass="Group" vgap="5.0">
                                            <children>
                                                <Label maxHeight="1.7976931348623157E308" text="1st Color" GridPane.vgrow="NEVER" />
                                                <ColorPicker fx:id="cpFirstRadialColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.vgrow="NEVER" />
                                                <Label maxHeight="1.7976931348623157E308" text="2nd Color" GridPane.rowIndex="1" GridPane.vgrow="NEVER" />
                                                <ColorPicker fx:id="cpSecondRadialColor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.vgrow="NEVER" />
                                            </children>
                                            <columnConstraints>
                                                <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
                                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0"/>
                                            </columnConstraints>
                                            <rowConstraints>
                                                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                                                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                                            </rowConstraints>
                                        </GridPane>
                                    </content>
                                </Tab>
                                <Tab closable="false" text="Size and Position">
                                    <content>
                                        <GridPane hgap="5.0" styleClass="Group" vgap="5.0">
                                            <children>
                                                <Label text="H Position" />
                                                <Label text="V Position" GridPane.rowIndex="1" />
                                                <Label text="Radius" GridPane.rowIndex="2" />
                                                <Slider fx:id="sliderHPos" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="1.0" showTickMarks="true" GridPane.columnIndex="1" />
                                                <Slider fx:id="sliderVPos" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="1.0" showTickMarks="true" value="1.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                                                <Slider fx:id="sliderRadius" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="1.0" showTickMarks="true" value="1.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                                            </children>
                                            <columnConstraints>
                                                <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
                                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                            </columnConstraints>
                                            <rowConstraints>
                                                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                                                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                                                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                                            </rowConstraints>
                                        </GridPane>
                                    </content>
                                </Tab>
                            </tabs>
                        </TabPane>
                    </children>
                </StackPane>
            </children>
            <columnConstraints>
                <ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" />
            </columnConstraints>
            <rowConstraints>
                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" vgrow="ALWAYS" />
            </rowConstraints>
        </GridPane>
    </content>
</Tab>
<Tab fx:id="tabBGStyle" closable="false" text="Background">
    <content>
        <DGCSDefiner/>
    </content>
</Tab>

共有1个答案

冯庆
2023-03-14

您不需要。jar文件来完成此操作。您可以简单地用它创建新的FXML文件。组合框。创建类文件,扩展组合框,控制器和添加控制器在FXML文件(在场景构建器)。

在scene builder搜索框左侧的组合框中找到“从JAR/FXML文件导入”,然后选择该文件。现在你有新的标题窗格在左手风琴与名称自定义。在那里你可以找到你的组件。

@编辑有文件。

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

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

<fx:root type="javafx.scene.layout.GridPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"  xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="MyGridPane.MyGridPaneController">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
</fx:root>
package MyGridPane;

import javafx.fxml.FXMLLoader;
import java.io.IOException;

/**
 * Created by Marcin on 2014-09-01.
 */
public class MyGridPane {
    MyGridPane(){
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MyGridPane.fxml"));
        fxmlLoader.setRoot(this); fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }
}
package MyGridPane;

import javafx.fxml.Initializable;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by Marcin on 2014-09-01.
 */
public class MyGridPaneController implements Initializable{
    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}

您可以添加这个组件。

 类似资料:
  • 我通过扩展现有控件创建了一个新控件,我希望在JavaFX场景中使用这个新控件。我希望能够使用Scene Builder编辑我的场景,但在将新控件添加到FXML文件后,我在打开Scene Builder时遇到。 例如,下面是我创建的一个类,它扩展了: 将此控件添加到FXML文件后... 为什么Scene Builder找不到我的新控件?我需要做什么才能让它找到并能够使用我的新控件? 如果需要,下面是

  • 几个星期以来,我一直在想办法解决这个问题,现在我开始放弃了。我肯定做了什么根本错误的事情。不管怎样,这是我的情况。我以前用JavaFX做了一个简单的小程序,但现在发现了Scene Builder,并想用这个工具重新构建它。该项目包括几个经常重用的组件,如下面的组件。它由一个标签、一个滑块、一个文本字段和另一个自定义组件InfoIcon组成。 我已经了解到,在构建我称之为SliderVariable

  • 我使用一个fxml文件和一个Java类实现了一个自定义控件,类似于本官方教程中所解释的内容(参见下面的代码)。请注意,fxml根元素是用定义的,我以编程方式调用。 我尝试在应用程序的FXML布局中包含控件,应用程序加载良好(并按预期显示控件)。 但是,如果我尝试在Scene Builder 2.0中导入包含控件的jar文件,则该控件不会出现在要导入的组件列表中(与同一jar中的其他一些控件不同)。

  • 我的自定义类: 然后尝试添加这个自定义类,如下所示: 我已经尝试搜索这个错误,但没有找到任何解释为什么这不应该工作。我找到的示例表明,应该可以从control类扩展,并将其直接导入到fxml文件中,事实确实如此。当运行程序时,它的工作是完美的,这是场景构建器的问题。 我意识到这是一个Java版本问题,但整个项目设置为Java9(53),我尝试过更改版本,但没有成功。

  • 我希望此图表显示在场景生成器上。怎么可能。。??

  • 我使用scene builder(Gluon scene Builder-JavaFX scene Builder8.1.1)创建应用程序的UI并使用Eclipse开发JavaFX。 现在...每次我在scene builder中保存一些东西时,它都会从fxml文件中删除我自己的类的导入。有没有一种方法告诉scene builder那些类属于项目来避免这种行为?