2014-09-06 134 views
-1

HiEveryone,如何在位置顶部设置TextField?

我在JavaFx是新的,我TextField显示在画面的中间,但不是在顶部的位置。我认为哪里错了?请帮助..

看一看这个截图..

enter image description here

,但我想设置文本字段顶部..

这里的源代码:

package sample; 

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.GridPane; 
import javafx.scene.web.WebEngine; 
import javafx.scene.web.WebView; 
import javafx.stage.Stage; 
import javafx.scene.control.TextField; 

public class Main extends Application { 
    @Override 
    public void start (Stage primaryStage){ 
     primaryStage.setTitle("Modern web browser."); 
     WebView wv = new WebView(); 
     WebEngine we = wv.getEngine(); 
     we.load("http://www.google.com/"); 

     TextField tf = new TextField("http://www.google.com/"); 
     tf.setMaxHeight(Double.MIN_VALUE); 
     GridPane sp = new GridPane(); 
     sp.getChildren().add(wv); 
     sp.getChildren().add(tf); 

     Scene scene = new Scene(sp, 600, 500); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

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

请帮助..感谢高级!

EDITED

由于@Nagesh库马尔回答我使用VBox收到此错误后:

enter image description here

回答

1

从GridPane更改您的布局,以垂直框如下

VBox vbox = new VBox(); 

现在首先添加你的TextField,这样它就会像fol一样在最前面低点

vbox.getChildren().add(tf); 

那么的WebView如下

vbox.getChildren().add(wv); 

编辑: 是的,你可以尝试把在垂直框

+0

好W8请控制之间的这种

VBox vbox = new VBox(5); 

5像素的空间。 。我正在尝试这个 – 2014-09-06 07:36:19

+0

终于工作谢谢.... :) – 2014-09-06 07:52:13

+0

还有一件事窝窝呃喜欢问..我们可以给它们之间的空间..看看这[SCREENSHOT]中的蓝线(http://postimg.org/image/wbl9ofvxf/) – 2014-09-06 07:55:20

相关问题