1

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?

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107

1 Answers1

3

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.

James_D
  • 201,275
  • 16
  • 291
  • 322
  • Updating to Java 8 did indeed fix the problem. Does this mean that my users will have to have Java 8 for it to work? Is there another way around this? – Kevin Workman May 14 '14 at 18:26
  • You could mess with column constraints to see if you can find a workaround, but requiring Java 8 is probably the only sure-fire way to make it work. Depending on your deployment requirements, you could consider use a ["self contained package"](http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm) to ensure the Java version. – James_D May 14 '14 at 18:30
  • Thanks, that looks promising! – Kevin Workman May 14 '14 at 18:32