2014-09-01 4 views
5

Je travaillais sur une scène quand j'ai remarqué que j'avais pratiquement la même chose trois fois. Plutôt que cela (puisque je déteste ça), j'ai décidé de prendre ce que j'avais ces 3 fois et de le transformer en un composant personnalisé. Maintenant je sais que je peux l'ajouter dans le code mais je ne peux pas prédire le comportement de la mise en page (deux d'entre eux iront directement dans les onglets, et le troisième ira dans un volet de la grille).Est-il possible d'importer un fichier JAR contenant un contrôle JavaFX personnalisé dans Scene Builder?

J'ai essayé d'importer le fichier .jar contenant le contrôle dans Scene Builder. Une boîte de dialogue est apparue me demandant ce que je voulais importer dans le fichier JAR mais il était complètement vide.

J'ai vu précédemment que certains individus ont ajouté des "contrôles personnalisés" (un terme que j'utilise vaguement) seulement pour trouver que, fondamentalement, il ne fait que copier un ensemble de composants pour former le contrôle. Cela peut fonctionner pour certaines personnes mais je ne cherche pas cela. Pour clarifier

ce que je ne veux (si je regarde dans le code FXML):

<DGCSDefiner //other layout related XML code/> 

ce que je ne veux pas:

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

Est-ce possible? Je sors de C# et VS2010 encore et je suis un peu gâté quand il s'agit de contrôles personnalisés, donc s'il est possible de faire quelque chose comme ça, quelqu'un peut-il me dire comment?

Est-il possible d'importer un fichier JAR compilé contenant un contrôle JavaFX personnalisé dans Scene Builder, de sorte que le faire tomber de la bibliothèque aboutira à ce que j'ai décrit là-haut?

EDIT 1 Ok c'est ce que j'ai dans mon fichier FXML. Selon mlody991, j'ai besoin 3 fichiers pour faire ce travail: Le fichier FXML (Construit avec SceneBuilder):

<?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> 

Le fichier de classe Java (qui représentera l'objet réel dans le code):

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.fxml'."; 
     //</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); 
     } 
    } 
} 

Et puis ce dernier fichier, dont le but me échappe:

/* 
* 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) { 

    } 
} 

Est-il possible que quelqu'un me expliquer le but de ce dernier fichier? Quelle est sa fonction? Je peux voir à partir de l'exemple de code avec lequel j'ai été fourni qu'il a été défini comme le contrôleur FXML mais cela ne me dit toujours rien. Je n'ai jamais vraiment configuré un contrôleur FXML auparavant car je le fais généralement dans du code, alors est-ce que c'est explicitement pour rendre ce contrôle importable dans Scene Builder?

EDIT 2 OK. J'ai eu une intuition et cela s'est avéré correct mais ça n'a pas aidé. J'ai supprimé la référence de feuille de style CSS de contrôle et cela m'a permis d'ajouter le contrôle, pas de problème.

Cependant quand je laissai tomber dans c'était ce qui se passait dans le fichier FXML:

Il est passé de cette (partie pertinente uniquement représentée):

<Tab fx:id="tabBGStyle" closable="false" text="Background" /> 

à ceci:

<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> 

qui est exactement ce que je veux .

Ce que je voudrais voir est quelque chose à l'effet de ceci:

<Tab fx:id="tabBGStyle" closable="false" text="Background"> 
    <content> 
     <DGCSDefiner/> 
    </content> 
</Tab> 

dans le code FXML après que je fais glisser le contrôle personnalisé dans le concepteur. Est-ce possible? Ai-je besoin de le compiler dans un pot?

Edit 3 Pour le rendre un peu plus clair, this est exactement ce que je veux voir se produire. Cela semble bien, mais le problème est qu'il n'y a pas d'informations sur la façon d'importer un contrôle personnalisé dans Scene Builder de telle sorte que lorsque je le glisse sur le canevas, je n'obtiens quelque chose que dans le voisinage d'une ligne de code. livre et demi il est écrit (ce qui est juste idiot si je voulais que je pourrais (et le ferais) le faire moi-même).

Répondre

5

Vous n'avez pas besoin de fichier .jar pour le faire. Vous pouvez simplement créer un nouveau fichier FXML avec ce dont vous avez besoin. boîte combo. Créez un fichier de classe avec une zone de liste déroulante étendue, un contrôleur et un contrôleur d'ajout dans un fichier FXML (dans le générateur de scènes). Trouvez "Import from JAR/FXML file" dans la zone de liste déroulante près de la boîte de recherche de gauche dans le générateur de scènes, puis sélectionnez le fichier. Vous avez maintenant un nouveau volet titre dans l'accordéon gauche avec le nom Custom. Là, vous pouvez trouver vos composants.

@edit Il existe des fichiers.

MyGridPane.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> 

MyGridPane.java

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); 
     } 
    } 
} 

MyGridPaneController.java

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) { 

    } 
} 

L'étape suivante est d'ajouter à la scène Builder

enter image description here

et vous pouvez ajouter ce composant.

enter image description here

+0

Essayé cela. Vous avez un message disant "Les objets ne peuvent pas être ajoutés à la bibliothèque parce qu'ils ne sont pas autonomes". – Will

+0

try added code;) –

+0

Sauf que le contrôle est trop simplifié par rapport à celui avec lequel je travaille. Je ne sais pas si ça marcherait. Mon contrôle est en fait un tas de composants organisés ensemble que je veux pouvoir réutiliser encore et encore, et ce que je vois que vous avez est juste une grille. Est-ce que mettre des contrôles dans ce GridPane le rendrait importable, ou échouerait-il encore complètement? – Will

Questions connexes