2014-07-07 17 views
5

This code एक 3 डी दृश्य बनाएगा जो 300x300 बड़ा है। जब मैं युक्त विंडो/चरण का आकार बदलता हूं तो व्यूपोर्ट का आकार बदल नहीं जाएगा।जावाएफएक्स 3 डी सबसेन का आकार कैसे बदलें?

Parent में width या height गुण नहीं हैं। मैं बदलने वाले विंडो आकार में Parent और/या SubScene के आकार को कैसे समायोजित करूं?

उत्तर

9

यह बाँध माता पिता

SubScene subscene = new SubScene(root, 1024, 768, true, null); 
subscene.setFill(Color.GREY); 
subscene.setCamera(camera); 
StackPane stackPane = new StackPane(); 
stackPane.getChildren().add(subscene); 
subscene.heightProperty().bind(stackPane.heightProperty()); 
subscene.widthProperty().bind(stackPane.widthProperty()); 
+0

मैं कुछ समय पहले कि बारे में पता चला, लेकिन धन्यवाद: इसके अलावा subScene अपने फलक से एक अलग आकार हो सकता है। – fho

+0

अभिभावक वर्ग में ऊंचाई नहीं हैप्रॉपर्टी() या चौड़ाईप्रॉपर्टी()। – Arceus

+0

आप किस मूल वर्ग का उपयोग कर रहे हैं? क्या आप पैरेंट क्लास के अंदर एक स्टैकपैन जोड़ सकते हैं और फिर सबसिन्स बांध सकते हैं? – MitchBroadhead

3

को मैंने पाया यह भी गलत पर SubScene वस्तु की कामयाब गुण सेट करने के लिए महत्वपूर्ण है।

subscene.setManaged(false); 

इस तरह, SubScene वस्तु के आकार अपनी मूल StackPane वस्तु के आकार पर असर नहीं पड़ेगा और आकार बदलने के भी जब StackPane वस्तु के आकार को कम करने के लिए काम करेंगे।

+0

बस उप दृश्य को कम करने के लिए मुझे क्या चाहिए – Josephus87

0

निम्नलिखित दृष्टिकोण के साथ आप अपनी सबससीन को किसी भी वर्ग में डाल सकते हैं जो फलक वर्ग (जैसे सीमावर्ती, ग्रिडपेन इत्यादि) को बढ़ाता है। फिर भी

public class GuiControler extends BorderPane implements Initializable,ChangeListener { 

    //Set a changeListener to the Stage's Window and Implement the ChangeListener in the class where you want to make the subScene scaling. 

    stage.widthProperty().addListener(this); 
    stage.heightProperty().addListener(this); 

//.... 


    @Override 
      public void changed(ObservableValue observable, Object oldValue, Object newValue) { 
       double width = stage.getWidth(); 
       double height = stage.getHeight(); 
       if(observable.equals(this.widthProperty())) { 
        double scale = width/400; // 400 is my initial width size of the stage (main java app window) window 
        subScene.setWidth(200*scale); // 200 is my initial size of the subscene window 
       }else if(observable.equals(this.heightProperty())){ 
        double scale = height/400; // 400 is initial size for stage height window 
        subScene.setHeight(250*scale); // 250 is initial size for subScene width 
       } 
      } 
      } 
संबंधित मुद्दे