Pergunta

I have the following example code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Test extends Application {


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

    @Override
    public void start(Stage primaryStage) {


        primaryStage.setTitle("JavaFX Test");

        GridPane grid = new GridPane();
        grid.add(new Text("Enter the value in the text box below:"), 0, 0, 3, 1);

        grid.add(new Text("Label: "), 0, 1);
        grid.add(new TextField(), 1, 1);
        grid.add(new Text("units"), 2, 1);

        Scene scene = new Scene(grid);
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();
        primaryStage.show();
    }
}

Which results in the following window:

JavaFX Window

If I resize the window to the width I would expect it to be, the TextField is also resized:

Resized JavaFX Window

My question is, where is that white space on the right of the window coming from? Why is the window size so much wider than the space taken up by the components? Why is the TextField resized when I make my window smaller, even though the window has plenty of room for it?

If I remove the top Text, the window size is more sane:

JavaFX Window sans top Text

I've tried using VBox and HBox to achieve the effect I'm looking for, but the window always seems to look like the first image above. What's going on?

Foi útil?

Solução

This looks like a known bug: RT24636. It is fixed in the latest release (Java 1.8.0_05).

No workaround is posted on the JIRA and none comes to mind immediately.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top