2014-09-01 8 views
5

मैं एक मंच पर काम कर रहा था जब मैंने देखा कि मेरे पास व्यावहारिक रूप से एक ही चीज़ तीन बार थी। इसके बजाय (जब से मैं उससे नफरत करता हूं), मैंने फैसला किया कि मेरे पास 3 बार क्या था और इसे एक कस्टम घटक में बदल दिया।क्या सीनियर बिल्डर में एक कस्टम जावाएफएक्स नियंत्रण वाला एक जार आयात करना संभव है?

अब मुझे पता है कि मैं इसे कोड में जोड़ सकता हूं लेकिन मैं लेआउट व्यवहार की भविष्यवाणी नहीं कर सकता (इनमें से दो सीधे टैब में जा रहे हैं, और तीसरा एक ग्रिड फलक में जा रहा है)।

मैंने उस .jar को आयात करने का प्रयास किया जिसमें दृश्य बिल्डर में नियंत्रण था। एक संवाद ने मुझे पूछा कि जेएआर में मैं क्या आयात करना चाहता था लेकिन यह पूरी तरह से खाली था।

मैंने देखा है कि कुछ लोगों ने "कस्टम नियंत्रण" (एक शब्द जिसे मैं कम से कम उपयोग करता हूं) जोड़ दिया है, केवल यह पता लगाने के लिए कि मूल रूप से यह नियंत्रण बनाने के लिए घटकों के समूह को एक साथ डंप करता है। यह कुछ लोगों के लिए काम कर सकता है लेकिन मैं इसकी तलाश नहीं कर रहा हूं।

स्पष्ट करने के लिए मैं क्या (मैं FXML कोड की जांच के लिए गए थे) चाहते हैं:

<DGCSDefiner //other layout related XML code/> 

क्या मैं नहीं चाहता हूँ:

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

यह संभव है? मैं फिर से सी # और वीएस -2010 से बाहर आ रहा हूं और जब कस्टम नियंत्रण की बात आती है तो मैं थोड़ी खराब हो जाती हूं, इसलिए ऐसा कुछ करने के लिए संभव है, क्या कोई मुझे बता सकता है कि कैसे?

क्या सीनियर बिल्डर में एक कस्टम जावाएफएक्स नियंत्रण युक्त एक संकलित जेएआर फ़ाइल आयात करना संभव है, जैसे पुस्तकालय से इसे छोड़ना परिणामस्वरूप मैंने वहां वर्णित किया होगा?

संपादित करें 1 ठीक है मेरे पास मेरी FXML फ़ाइल में है। mlody991 के अनुसार, मैं इस काम करने के लिए 3 फ़ाइलों की जरूरत है: FXML फ़ाइल (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> 

जावा वर्ग फ़ाइल (जो कोड में वास्तविक वस्तु का प्रतिनिधित्व करेंगी):

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

और फिर यह पिछले फ़ाइल, उद्देश्य जिनमें से मुझे eludes:

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

    } 
} 

क्या यह संभव है किसी ने मुझे यह पिछले फ़ाइल के प्रयोजन की व्याख्या करने के लिए? यह क्या काम है? मैं उदाहरण कोड से देख सकता हूं जिसके साथ मुझे प्रस्तुत किया गया था इसे इसे FXML नियंत्रक के रूप में सेट किया गया है लेकिन यह अभी भी मुझे कुछ भी नहीं बताता है। मैंने वास्तव में कभी भी एफएक्सएमएल नियंत्रक को पहले कभी भी सेट नहीं किया है क्योंकि मैं आमतौर पर इसे कोड में करता हूं, इसलिए क्या यह उद्देश्य स्पष्ट रूप से दृश्य निर्माता में आयात करने योग्य है?

EDIT 2 ठीक है। मेरे पास एक झटका था और यह सही साबित हुआ लेकिन इससे मदद नहीं मिली। मैंने नियंत्रण सीएसएस स्टाइलशीट संदर्भ हटा दिया और इसने मुझे नियंत्रण जोड़ने की अनुमति दी, कोई समस्या नहीं।(प्रासंगिक भाग केवल दिखाया गया है)

यह इस से चला गया:

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

लेकिन जब मैं इस में गिरा दिया क्या FXML फ़ाइल में हुआ था

जो वास्तव में मैं नहीं चाहता हूं। के बाद मैं खींचें और डिजाइनर में कस्टम नियंत्रण छोड़ FXML कोड में

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

:

मैं देखना चाहेंगे क्या इस के प्रभाव के लिए कुछ न कुछ है। क्या यह संभव है? क्या मुझे इसे जार में संकलित करने की ज़रूरत है?

संपादित 3 यह थोड़ा और अधिक स्पष्ट करने के लिए, this वास्तव में क्या मैं ऐसा देखना चाहते है। यह अच्छा लग रहा है लेकिन समस्या यह है कि दृश्य बिल्डर में कस्टम नियंत्रण आयात करने के बारे में कोई जानकारी नहीं है, जैसे कि जब मैं इसे 'कैनवास पर छोड़ देता हूं, तो मुझे केवल कोड की एक पंक्ति के पड़ोस में कहीं मिलता है, बनाम किताब और आधा यह लिखना (जो सिर्फ मूर्खतापूर्ण है। अगर मैं चाहता था कि मैं इसे (और करूंगा) कर सकता हूं)।

उत्तर

5

आपको ऐसा करने के लिए .jar फ़ाइल की आवश्यकता नहीं है। आप बस नई FXML फ़ाइल बना सकते हैं जिसके साथ आपको पूर्व की आवश्यकता है। सम्मिश्रण पटी। कॉम्बो बॉक्स, कंट्रोलर को विस्तारित करने और FXML फ़ाइल (दृश्य बिल्डर में) में नियंत्रक जोड़ने के साथ क्लास फ़ाइल बनाएं।

दृश्य निर्माता में बाएं खोज बॉक्स के पास कॉम्बो बॉक्स में "JAR/FXML फ़ाइल से आयात करें" ढूंढें और फिर फ़ाइल का चयन करें। अब आपके पास नाम कस्टम के साथ बाएं accordion में नया शीर्षक फलक है। वहां आप अपने घटकों को पा सकते हैं।

@edit फाइलें हैं।

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

    } 
} 

अगला चरण दृश्य बिल्डर को

जोड़ने है

और आप इस घटक को जोड़ सकते हैं।

enter image description here

+0

कोशिश की। एक संदेश मिला "ऑब्जेक्ट्स को लाइब्रेरी में जोड़ा नहीं जा सकता क्योंकि वे स्वयं निहित नहीं हैं"। – Will

+0

जोड़ा गया कोड आज़माएं;) –

+0

सिवाय इसके कि उस नियंत्रण की तुलना में उस पर नियंत्रण अधिक सरल है, जिसके साथ मैं काम कर रहा हूं। मुझे नहीं पता कि यह काम करेगा। मेरा नियंत्रण प्रभावी रूप से संगठित घटक का एक गुच्छा है जिसे मैं बार-बार उपयोग करने में सक्षम होना चाहता हूं, और जो कुछ मैं देखता हूं वह सिर्फ एक ग्रिड फलक है। उस ग्रिडपेन में नियंत्रण डालने से यह आयात योग्य हो जाएगा, या फिर भी यह पूरी तरह विफल हो जाएगा? – Will

संबंधित मुद्दे