2010-08-07 74 views
0

我有一個關於JavaFX佈局的問題,以下是我的代碼,你可以直接運行代碼:關於JavaFX佈局

import javafx.scene.Scene; 
import javafx.scene.control.Button; 

import javafx.scene.layout.VBox; 
import javafx.scene.control.TextBox; 
import javafx.scene.layout.HBox; 
import javafx.scene.paint.Color; 

import javafx.scene.Group; 
import javafx.scene.shape.Rectangle; 

import javafx.stage.Stage; 

/** 
* @author Administrator 
*/ 
var headerHeight: Number = 50; 
var header: Group = Group { 
      var searchBox: HBox; 
      content: [ 
       Rectangle { 
        width: bind scene.width; 
        height: bind headerHeight; 
        fill: Color.BLUE 
       }, 
       searchBox = HBox { 
          spacing: 10 
          layoutY: bind (headerHeight - searchBox.layoutBounds.height)/2; 
          layoutX: bind scene.width - searchBox.layoutBounds.width - 20; 
          var textBox: TextBox; 
          content: [ 
           textBox = TextBox { 
              promptText: "please input search key" 
              columns: 20 
              selectOnFocus: true 
             }, Button { 
            text: "search" 
            strong: true 
            action: function() { 
             println("Button clicked"); 
            } 
           }] 
         } 
      ] 
     } 
var rect = Rectangle { 
      width: bind 400; 
      height: bind 80; 
      fill: Color.YELLOW 
     } 
var footerHeight: Number = 50; 
var footer: Group = Group { 
      var bounds: Rectangle; 
      content: [ 
       bounds = Rectangle { 
          width: bind scene.width; 
          height: bind footerHeight; 
          fill: Color.RED 
         } 
      ] 
     } 
var scene: Scene = Scene { 
      content: [ 
       VBox { 
        content: [ 
         header, 
         rect, 
         footer 
        ] 
       } 
      ] 
     } 

function run() { 
    Stage { 
     scene: scene 
    } 
} 

場景的高度是不正常的。頁腳的高度是50,但似乎只有約30.

有什麼不對,有什麼建議嗎?

謝謝。

回答

0

出於某種原因,場景未調整大小以適合全部內容。我不知道爲什麼,但你可以通過設置scene.height = headerHeight + 80 + footerHeight來解決這個問題。

0

嘗試綁定到Stage而不是Scene