2015-04-04 59 views
1

相關代碼如何,使其適合在JavaFX的整個屏幕

package whowantstobeamillionairetriviagame; 

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.image.Image; 
import javafx.scene.layout.Background; 
import javafx.scene.layout.BackgroundImage; 
import javafx.scene.layout.BackgroundPosition; 
import javafx.scene.layout.BackgroundRepeat; 
import javafx.scene.layout.BackgroundSize; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

public class WhoWantsToBeAMillionaireTriviaGame extends Application 
{ 
@Override 
public void start(Stage startingStage) throws Exception 
{  
    Image backgroundColor = new Image("http://www.sonomare.com/darkblue_background_rot_180.jpg"); 

    BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false); 
    BackgroundImage backgroundImage = new BackgroundImage(backgroundColor, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize); 

    StackPane background = new StackPane(); 
    background.setBackground(new Background(backgroundImage)); 

    Scene menuScene = new Scene(background); 
    startingStage.setScene(menuScene); 
    startingStage.setFullScreen(true); 
    startingStage.show(); 
} 

public static void main(String[] args) 
{ 
    launch(args); 
} 
} 

我這麼問是因爲重複使用會造成畫面一遍遍在x和y軸重複因此它可以拉伸圖片適合整個屏幕。不使用重複會在其周圍留下一堆空白空間。 Round,Space和將舞臺設置爲全屏也無濟於事。我能做什麼?

回答

0

您可以將背景大小設置爲封面。

從文檔

大小可能與蓋=真,這意味着圖像應被拉伸以覆蓋該區域的整個渲染表面來限定。

定義爲BackgroundSize成爲

BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, true); 
+0

謝謝主席先生,看起來好多了。 – 2015-04-04 20:42:31