Automatic resizing of controls in javafx2

I am trying to add a ToolBar control, containing 2 Buttons and a TextField in my scene graph. I want that the TextField control gets automatically resized and acquire all the space available into toolbar. So, I used the HBox layout control to add the buttons and textfield. I did as followed:

ToolBar tb = new ToolBar();
    HBox hbox = new HBox(8);
    TextField tf = new TextField();
    HBox.setHgrow(tf, Priority.ALWAYS);
    hbox.getChildren().add(new Button("<-"));
    hbox.getChildren().add(new Button("->"));
    hbox.getChildren().add(tf);            
    tb.getItems().add(hbox);

But its not working. Where am I going wrong? Please help.

Answers


You can try next:

    ToolBar tb = new ToolBar();
    TextField tf = new TextField();
    HBox hbox = new HBox(8);
    hbox.prefWidthProperty().bind(tb.widthProperty().subtract(20));
    HBox.setHgrow(tf, Priority.ALWAYS);
    hbox.getChildren().add(new Button("<-"));
    hbox.getChildren().add(new Button("->"));
    hbox.getChildren().add(tf);
    tb.getItems().add(hbox);

Need Your Help

ASP.NET 4.5 How to Create Custom Log-ins?

c# asp.net login identity

I am relatively new to ASP.NET so I am hoping someone can help point me in the right direction.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.