layout - JavaFX Resizing VBOX dynamically -
i having problems vbox, looked other questions me, sadly nothing worked. have vbox bunch of slider , buttons, , happens can rezise pretty want. can make small buttons inside disappear, or can make big cover other parts of program. tried vbox.setmaxsize , vbox.setminxsize, nothing happed. should buttons , sliders inside it? though since buttons , sliders vbox childrem, changes made on vbox them also. post controller class followed fxml file, fell free tell me if other classes needed. thank much.
controller
package fotofinish; import java.io.file; import java.net.url; import java.util.resourcebundle; import java.util.logging.level; import java.util.logging.logger; import javafx.application.platform; import javafx.beans.value.observablevalue; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.colorpicker; import javafx.scene.control.radiobutton; import javafx.scene.control.scrollpane; import javafx.scene.control.slider; import javafx.scene.control.togglegroup; import javafx.scene.image.imageview; import javafx.scene.layout.priority; import javafx.scene.layout.vbox; import javafx.stage.filechooser; import javafx.stage.filechooser.extensionfilter; import javafx.stage.stage; //todo: find better way have image refreshed public class fxmldocumentcontroller implements initializable { private static final logger logger = logger.getlogger(fotofinish.fxmldocumentcontroller.class.getname()); stage stage; private fotofinishmodel model = new fotofinishmodel(); @fxml private slider brightnessslider; @fxml private slider contrastslider; @fxml private togglegroup brushtyperadiogroup; @fxml private radiobutton brushtypecircleradiobutton; @fxml private radiobutton brushtypespraypaintradiobutton; @fxml private radiobutton brushtypesquareradiobutton; @fxml private colorpicker brushcolorpicker; @fxml private numberfieldfx brushsizenumberfield; @fxml private imageview imageviewer; @fxml private scrollpane imagescrollpane; @fxml private vbox vbox; @override public void initialize(url url, resourcebundle rb) { //todo: block increment? this.brightnessslider.valueproperty().addlistener((observablevalue<? extends number> observable, number oldvalue, number newvalue) -> { if(model.changebrightness(newvalue.doublevalue())) { this.refreshimageviewer(); } }); //todo: convert dragged call this.contrastslider.valueproperty().addlistener((observablevalue<? extends number> observable, number oldvalue, number newvalue) -> { if (model.changecontrast(newvalue.doublevalue())) { this.refreshimageviewer(); } }); } @fxml private void filtergrayscale(actionevent ignored) { model.applygrayscalefilter(); this.refreshimageviewer(); this.resetsliders(); } @fxml private void filtersepia(actionevent ignored) { model.applysepiafilter(); this.refreshimageviewer(); this.resetsliders(); } @fxml private void filterinstant(actionevent ignored) { model.applyinstantfilter(); this.refreshimageviewer(); this.resetsliders(); } @fxml private void filtercustom(actionevent ignored) { //todo: code create custom filter popup , arguments custom filter logger.log(level.info, "todo: custom filter popup launched"); model.applycustomfilter(); this.refreshimageviewer(); this.resetsliders(); } @fxml private void filternone(actionevent ignored) { model.resetimagetooriginal(); this.refreshimageviewer(); this.resetsliders(); } @fxml private void brushtypecircle(actionevent ignored) { model.setbrushtypecircle(); } @fxml private void brushtypesquare(actionevent ignored) { model.setbrushtypesquare(); } @fxml private void brushtypespraypaint(actionevent ignored) { model.setbrushtypespraypaint(); } @fxml private void helpdoc(actionevent ignored) { logger.log(level.info, "todo: document launched"); } @fxml private void aboutdialog(actionevent ignored) { logger.log(level.info, "todo: dialog created"); } @fxml private void brushcolor(actionevent ignored) { model.changebrushcolor(this.brushcolorpicker.getvalue()); } @fxml private void brushsize(actionevent ignored) { model.changebrushsize(integer.parseint(this.brushsizenumberfield.gettext())); } //todo: make title setting more intelligent @fxml private void open(actionevent ignored) { logger.log(level.info, "open file chooser launched"); filechooser filechooser = new filechooser(); filechooser.settitle("open image"); filechooser.getextensionfilters().add(new extensionfilter("image files", "*.png")); //todo: add other types file selectedfile = filechooser.showopendialog(null); //todo: needs value in order block main window if (selectedfile != null) { logger.log(level.info, "file {0} choosen in open file chooser", selectedfile); model.loadimage(selectedfile); this.refreshimageviewer(); this.stage.settitle("foto finish - " + selectedfile); } else { logger.log(level.info, "no file selected in open file chooser"); } } @fxml private void gallerybutterfly(actionevent ignored) { model.loadgallerybutterflyimage(); this.refreshimageviewer(); } @fxml private void galleryteddybear(actionevent ignored) { model.loadgalleryteddybearimage(); this.refreshimageviewer(); } @fxml private void galleryprincess(actionevent ignored) { model.loadgalleryprincessimage(); this.refreshimageviewer(); } @fxml private void galleryfirefighter(actionevent ignored) { model.loadgalleryfirefighterimage(); this.refreshimageviewer(); } @fxml private void save(actionevent ignored) { model.saveimage(); } @fxml private void saveas(actionevent ignored) { logger.log(level.info, "save file chooser launched"); filechooser filechooser = new filechooser(); filechooser.settitle("save image"); filechooser.getextensionfilters().add(new extensionfilter("image files", "*.png")); //todo: add other types file selectedfile = filechooser.showsavedialog(null); //todo: needs value in order block main window if (selectedfile != null) { logger.log(level.info, "file {0} choosen in save file chooser", selectedfile); model.saveimageas(selectedfile); } else { logger.log(level.info, "no file selected in save file chooser"); } } @fxml private void quit(actionevent ignored) { logger.log(level.info, "quitting"); platform.exit(); //todo: make detect unsaved changes } @fxml private void newfile(actionevent ignored) { logger.log(level.info, "todo: new file created"); } private void refreshimageviewer() { this.imageviewer.setimage(model.getimage()); logger.log(level.info, "image refreshed"); } //todo: make connect better fxml default value private void resetsliders() { this.brightnessslider.setvalue(0); this.contrastslider.setvalue(0); logger.log(level.info, "brightness , contrast sliders reset"); } public void setstage(stage stagefrommain) { this.stage = stagefrommain; } }
fxml
<?xml version="1.0" encoding="utf-8"?> <?import javafx.geometry.*?> <?import javafx.scene.input.*?> <?import javafx.scene.image.*?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <borderpane maxheight="-infinity" maxwidth="-infinity" minheight="500.0" minwidth="600.0" prefheight="700.0" prefwidth="1200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fotofinish.fxmldocumentcontroller"> <top> <menubar prefheight="0.0" prefwidth="1034.0" borderpane.alignment="center"> <menus> <menu mnemonicparsing="false" text="file"> <items> <menuitem fx:id="menubarfilenew" mnemonicparsing="false" onaction="#newfile" text="new"> <accelerator> <keycodecombination alt="up" code="n" control="down" meta="up" shift="up" shortcut="up" /> </accelerator> </menuitem> <separatormenuitem mnemonicparsing="false" /> <menuitem fx:id="menubarfileopen" mnemonicparsing="false" onaction="#open" text="open"> <accelerator> <keycodecombination alt="up" code="o" control="down" meta="up" shift="up" shortcut="up" /> </accelerator> </menuitem> <menu mnemonicparsing="false" text="open gallery"> <items> <menuitem fx:id="menubarfilegallerybutterfly" mnemonicparsing="false" onaction="#gallerybutterfly" text="butterfly" /> <menuitem fx:id="menubarfilegalleryteddybear" mnemonicparsing="false" onaction="#galleryteddybear" text="teddy bear" /> <menuitem fx:id="menubarfilegalleryprincess" mnemonicparsing="false" onaction="#galleryprincess" text="princess" /> <menuitem fx:id="menubarfilegalleryfirefighter" mnemonicparsing="false" onaction="#galleryfirefighter" text="firefighter" /> </items> </menu> <separatormenuitem mnemonicparsing="false" /> <menuitem fx:id="menubarfilesave" mnemonicparsing="false" onaction="#save" text="save"> <accelerator> <keycodecombination alt="up" code="s" control="down" meta="up" shift="up" shortcut="up" /> </accelerator> </menuitem> <menuitem fx:id="menubarfilesaveas" mnemonicparsing="false" onaction="#saveas" text="save as"> <accelerator> <keycodecombination alt="up" code="s" control="down" meta="up" shift="down" shortcut="up" /> </accelerator> </menuitem> <separatormenuitem mnemonicparsing="false" /> <menuitem fx:id="menubarfilequit" mnemonicparsing="false" onaction="#quit" text="quit"> <accelerator> <keycodecombination alt="up" code="c" control="down" meta="up" shift="up" shortcut="up" /> </accelerator></menuitem> </items> </menu> <menu mnemonicparsing="false" text="help"> <items> <menuitem fx:id="menubarhelpfotofinishhelpmenuitem" mnemonicparsing="false" onaction="#helpdoc" text="foto finish help"> <accelerator> <keycodecombination alt="up" code="f1" control="up" meta="up" shift="up" shortcut="up" /> </accelerator></menuitem> <menuitem fx:id="menubarhelpaboutmenuitem" mnemonicparsing="false" onaction="#aboutdialog" text="about" /> </items> </menu> </menus> </menubar> </top> <center> <splitpane dividerpositions="0.14941569282136896" minheight="-infinity" minwidth="-infinity" prefheight="160.0" prefwidth="200.0" borderpane.alignment="center"> <items> <anchorpane minheight="0.0" minwidth="0.0" prefheight="160.0" prefwidth="100.0"> <children> <vbox fx:id="vbox" alignment="top_center" layoutx="-11.0" layouty="25.0" maxheight="1.7976931348623157e308" maxwidth="1.7976931348623157e308" minwidth="100.0" prefheight="200.0" prefwidth="100.0" anchorpane.bottomanchor="10.0" anchorpane.leftanchor="10.0" anchorpane.rightanchor="10.0" anchorpane.topanchor="10.0"> <children> <label fx:id="sliderlabel" alignment="top_left" text="sliders"> <padding> <insets left="10.0" /> </padding> </label> <gridpane alignment="center"> <columnconstraints> <columnconstraints halignment="center" hgrow="sometimes" maxwidth="104.0" minwidth="10.0" prefwidth="84.0" /> </columnconstraints> <rowconstraints> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> </rowconstraints> <children> <button fx:id="filtergrayscalebutton" contentdisplay="top" mnemonicparsing="false" onaction="#filtergrayscale" prefheight="25.0" prefwidth="84.0" text="grayscale" textalignment="center" gridpane.rowindex="1"> <opaqueinsets> <insets top="50.0" /> </opaqueinsets> </button> <button fx:id="filtersepiabutton" mnemonicparsing="false" onaction="#filtersepia" prefheight="25.0" prefwidth="83.0" text="sepia" gridpane.rowindex="2" /> <button fx:id="filterinstantbutton" mnemonicparsing="false" onaction="#filterinstant" prefheight="25.0" prefwidth="83.0" text="instant" gridpane.rowindex="3" /> <button fx:id="filtercustombutton" mnemonicparsing="false" onaction="#filtercustom" prefheight="25.0" prefwidth="82.0" text="custom" gridpane.rowindex="4" /> <button fx:id="filternonebutton" mnemonicparsing="false" onaction="#filternone" prefheight="25.0" prefwidth="82.0" text="none" gridpane.rowindex="5" /> </children> <padding> <insets left="10.0" /> </padding> </gridpane> <gridpane prefheight="271.0" prefwidth="176.0"> <columnconstraints> <columnconstraints halignment="center" hgrow="sometimes" minwidth="10.0" prefwidth="100.0" /> </columnconstraints> <rowconstraints> <rowconstraints maxheight="88.0" minheight="10.0" prefheight="35.0" vgrow="sometimes" /> <rowconstraints maxheight="290.0" minheight="26.0" prefheight="59.0" vgrow="sometimes" /> <rowconstraints maxheight="233.0" minheight="6.0" prefheight="40.0" /> <rowconstraints maxheight="127.0" minheight="28.0" prefheight="56.0" /> <rowconstraints maxheight="148.0" minheight="23.0" prefheight="34.0" /> <rowconstraints maxheight="124.0" minheight="41.0" prefheight="51.0" /> </rowconstraints> <children> <label fx:id="brightnesslabel" text="brightness" /> <label fx:id="contrastlabel" text="contrast" gridpane.rowindex="2" /> <slider fx:id="brightnessslider" max="1.0" min="-1.0" minortickcount="10" orientation="horizontal" showticklabels="true" showtickmarks="true" snaptoticks="true" gridpane.rowindex="1" /> <slider fx:id="contrastslider" max="1.0" min="-1.0" minortickcount="10" orientation="horizontal" showticklabels="true" showtickmarks="true" snaptoticks="true" gridpane.rowindex="3" /> <label text="saturation" gridpane.rowindex="4" /> <slider max="1.0" min="-1.0" minortickcount="10" showticklabels="true" showtickmarks="true" snaptoticks="true" gridpane.rowindex="5" /> </children> <padding> <insets left="10.0" right="10.0" /> </padding> </gridpane> <label fx:id="drawinglabel" text="drawing" /> <colorpicker fx:id="brushcolorpicker" onaction="#brushcolor" /> <label fx:id="brushtypelabel" text="brush type" /> <radiobutton fx:id="brushtypecircleradiobutton" mnemonicparsing="false" onaction="#brushtypecircle" selected="true" text="circle"> <togglegroup> <togglegroup fx:id="brushtyperadiogroup" /> </togglegroup> </radiobutton> <radiobutton fx:id="brushtypesquareradiobutton" mnemonicparsing="false" onaction="#brushtypesquare" text="square" togglegroup="$brushtyperadiogroup" /> <radiobutton fx:id="brushtypespraypaintradiobutton" mnemonicparsing="false" onaction="#brushtypespraypaint" text="spraypaint" togglegroup="$brushtyperadiogroup" /> <label fx:id="brushsizelabel" text="brush size" /> <fotofinish.numberfieldfx fx:id="brushsizetextfield" onaction="#brushsize" text="10" /> <label fx:id="filterslabel" text="filters" /> </children> </vbox> </children> </anchorpane> <anchorpane minheight="0.0" minwidth="0.0" prefheight="369.0" prefwidth="465.0"> <children> <scrollpane layoutx="145.0" layouty="111.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <content> <imageview fx:id="imageviewer" fitheight="577.0" fitwidth="1010.0" pickonbounds="true" preserveratio="true" /> </content> </scrollpane> </children> </anchorpane> </items> </splitpane> </center> </borderpane>
Comments
Post a Comment