java - How do I make GridPane fill the entire scene? (JavaFX SceneBuilder w/ Eclipse Luna) -


i found answer seems outdated or not applicable situation.

i (along remainder of class) trying resize gridpane fill entire scene. here looks in scenebuilder now:

gridpane doesn't fill full scene?

if cannot see image: it's image of 3x3 gridpane (the element in hierachy) "gray space" of remaining scene surrounding gridpane.

this main code:

    package pkgtictactoe;      import javafx.application.application; import javafx.stage.stage; import javafx.scene.scene; import javafx.scene.layout.gridpane; import javafx.fxml.fxmlloader;   public class main extends application {      @override     public void start(stage primarystage) {         try {             gridpane root = (gridpane)fxmlloader.load(getclass().getresource("tictactoe.fxml"));             scene scene = new scene(root,400,400);             scene.getstylesheets().add(getclass().getresource("application.css").toexternalform());             primarystage.setscene(scene);             primarystage.show();         } catch(exception e) {             e.printstacktrace();         }     }      public static void main(string[] args) {         launch(args);     } } 

this controller code:

package pkgtictactoe; import java.net.url; import java.util.resourcebundle; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.image.image; import javafx.scene.image.imageview; import javafx.scene.layout.gridpane;  public class tictactoecontroller implements initializable {      @fxml     private gridpane root;      @override     public void initialize(url arg0, resourcebundle arg1) {         image imagex = new image(getclass().getresource("/pkgtictactoe/x.gif").toexternalform());         image imageo = new image(getclass().getresource("/pkgtictactoe/o.gif").toexternalform());         (int = 0; < 3; i++) {             (int j = 0; j < 3; j++) {                 int status = (int)(math.random() * 3 );                 if (status == 0) {                 root.add(new imageview(imagex), j, i);                 }             else if (status == 1) {                 root.add(new imageview(imageo), j, i);                 }             }          }      } } 

this code in .fxml file (in our class not "mess" .fxml directly, manipulate these elements via scenebuilder, , code in controller):

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.gridpane?>  <gridpane fx:id="root" alignment="center" gridlinesvisible="true" maxheight="1.7976931348623157e308" maxwidth="1.7976931348623157e308" prefheight="301.0" prefwidth="465.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pkgtictactoe.tictactoecontroller">    <rowconstraints>       <rowconstraints minheight="10.0" prefheight="30.0" />       <rowconstraints minheight="10.0" prefheight="30.0" />       <rowconstraints minheight="10.0" prefheight="30.0" />    </rowconstraints>    <columnconstraints>       <columnconstraints minwidth="10.0" prefwidth="100.0" />       <columnconstraints minwidth="10.0" prefwidth="100.0" />       <columnconstraints minwidth="10.0" prefwidth="100.0" />    </columnconstraints> </gridpane> 

i have tried manipulating different elements of properties, layout, , code on right hand side, , have looked through menu options @ top -- there doesn't seem way make sucker fit! have thought of creating anchorpane place gridpane inside of, circumvents problem rather finding solution.

i prefer answer oriented towards using scenebuilder sake of remainder of class. however, if include code method, enjoy well, prefer work less gui , more directly keyboard.

thanks time, apologize if have left details out or did not enough research on own find similar question.

the root element of scene fill entire scene, when run application grid pane filling scene. (just try putting background color on it.) however, grid pane contains empty space. (what see in scenebuilder of course pretty arbitrary, scenebuilder knows fxml, , scene defined , sized externally that.)

what you're asking how make content of grid pane fill grid pane (i.e. want columns take of width of grid pane between them). notice have set 3 columns have preferred width of 100; since scene has width 400, leaves 100 pixels of unused space. (similarly rows.)

remove prefwidth setting on column constraints, , set column constraints have hgrow value of always. (similarly rows, prefheight , vgrow.)


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -