java - Center an unresizable pane in JavaFX-2 -
i'm trying make simple image viewing application in javafx-2, fxml , scene builder. first javafx application , i'm having trouble playing panes , layouts.
basically, want display image in original size (without being able zoom/resize), in absolute center of application. also, window should resizable, if image bigger window's size, want have scrollbars appear able see entire image.
a example of i'm trying create adobe photoshop layout: http://imgur.com/ils0lum.
this current layout: http://imgur.com/r7pjrvk. image represented black stack pane. scrollbars working, can't find way put stack pane in center.
i feel missing important, can please point me in right direction?
thanks!
edit: here fxml code: pastebin.com/cnxyekf1
you used anchorpane container scrollpane. if use stackpane instead, makes content center on default. however, stackpane, other pane, uses space can get, take space , not being centered @ all. solve this, put scrollpane inside group. group big children are, , can control width , height setting prefheight , prefwidth of scrollpane. heres fxml (i removed buttons onclick listeners simplicity of example):
<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.group?> <anchorpane id="anchorpane" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="700.0" prefwidth="700.0" xmlns:fx="http://javafx.com/fxml" fx:controller="test.stackoverflowcontroller"> <children> <vbox prefheight="687.0" prefwidth="710.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <toolbar prefwidth="600.0" style="-fx-base: firebrick"> <items> <button fx:id="btn_imgfromfile" mnemonicparsing="false" style="-fx-base: firebrick" text="load image file" /> <button fx:id="btn_imgfromwindow" mnemonicparsing="false" style="-fx-base: firebrick" text="load image window" /> <separator orientation="vertical" prefheight="21.0" /> <button fx:id="btn_loadinfo" mnemonicparsing="false" style="-fx-base: firebrick" text="load window info" /> <button fx:id="btn_saveinfo" mnemonicparsing="false" style="-fx-base: firebrick" text="save window info" /> </items> </toolbar> <stackpane fx:id="pane_main" prefheight="200.0" prefwidth="200.0" vbox.vgrow="always"> <children> <group> <scrollpane fx:id="scroll_pane" prefheight="200.0" prefwidth="200.0" anchorpane.bottomanchor="-1.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="1.0"> <content> <stackpane fx:id="stack_pane" prefheight="230.0" prefwidth="333.0" style="-fx-background-color: #000000;" /> </content> </scrollpane> </group> </children> </stackpane> </children> </vbox> </children> </anchorpane>
result:
Comments
Post a Comment