java - javaFX - resizing TextArea/other UI controls with main application window -
in javafx application need update handle window resizing. want when window gets bigger keep aligned same , have textarea grow proportionate window , similar when making smaller.
i set min , max height fit buttons on right-hand side (decreasing spacing little gets smaller).
i'm figuring out anchorpane not best option , hoping little guidance on better approach. text area using custom, extending styledtextarea (richtextfx api).
last spec want text field , button under text aligned text area , think pane make distance between textfield , button cumbersome approach (i planning on not making resizable).
image reference : text app image
any appreciated. if makes difference, entire layout inside borderpane center.
<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.anchorpane?> <?import javafx.scene.shape.*?> <?import javafx.scene.text.*?> <?scenebuilder-stylesheet ../application.css?> <anchorpane fx:id="leftpane" minwidth="-1.0" prefheight="582.0" prefwidth="855.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.textprocontroller"> <!-- todo add nodes --> <children> <vbox alignment="center_left" layoutx="649.0" layouty="0.0" prefheight="582.0" prefwidth="205.0" spacing="55.0" styleclass="right-split"> <children> <button mnemonicparsing="false" onaction="#handleloadtext" prefheight="21.0" prefwidth="160.0" text="load text"> <font> <font size="14.0" fx:id="x1" /> </font> </button> <button font="$x1" mnemonicparsing="false" onaction="#handlefleschindex" prefwidth="160.0" text="flesch index" /> <button font="$x1" mnemonicparsing="false" onaction="#handleeditdistance" prefheight="21.0" prefwidth="160.0" text="edit distance" /> <button mnemonicparsing="false" onaction="#handlemarkovtext" prefheight="25.0" prefwidth="160.0" text="generate markov text"> <font> <font size="13.5" /> </font> </button> <checkbox fx:id="spellingbox" font="$x1" mnemonicparsing="false" onaction="#handlespelling" text="spelling suggestions" /> <checkbox fx:id="autocompletebox" font="$x1" mnemonicparsing="false" onaction="#handleautocomplete" text="autocomplete" /> </children> <padding> <insets bottom="20.0" left="5.0" /> </padding> </vbox> <anchorpane layoutx="0.0" layouty="0.0" minheight="0.0" minwidth="0.0" prefheight="582.0" prefwidth="650.0" styleclass="left-split"> <children> <hbox alignment="center_left" layoutx="0.0" layouty="525.0" prefheight="32.0" prefwidth="642.0" spacing="15.0"> <children> <textfield fx:id="fleschfield" prefwidth="72.0" /> <label text="flesch index"> <font> <font name="system bold" size="14.0" /> </font> </label> <pane maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="32.0" prefwidth="322.0" /> <button font="$x1" mnemonicparsing="false" onaction="#handleclear" text="clear" /> </children> <padding> <insets left="39.0" /> </padding> </hbox> </children> </anchorpane> </children> </anchorpane>
import java.io.ioexception; import java.util.list; import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.geometry.pos; import javafx.stage.modality; import javafx.stage.stage; import javafx.scene.scene; import javafx.scene.control.alert; import javafx.scene.control.alert.alerttype; import javafx.scene.layout.anchorpane; import javafx.scene.layout.borderpane; import javafx.scene.layout.hbox; import javafx.scene.layout.vbox; import javafx.scene.text.text; public class mainapp extends application { private stage primarystage; private borderpane rootlayout; private launchclass launch; spelling.wordpath wp; textgen.markovtextgenerator mtg; // called @ start of application @override public void start(stage primarystage) { this.primarystage = primarystage; this.primarystage.settitle("textproapp"); //primarystage.setresizable(false); try { // load root layout fxml fxmlloader loader = new fxmlloader(mainapp.class.getresource("view/rootlayout.fxml")); rootlayout = (borderpane) loader.load(); scene scene = new scene(rootlayout); primarystage.setscene(scene); primarystage.show(); } catch(exception e) { e.printstacktrace(); } launch = new launchclass(); showtextproapp(); } /** * shows main textapplication scene */ public void showtextproapp() { try { // load fxml file , set center of main layout fxmlloader loader = new fxmlloader(getclass().getresource("view/textapplayout.fxml")); anchorpane textpropage = (anchorpane) loader.load(); rootlayout.setcenter(textpropage); // connect controller , main app textprocontroller controller = loader.getcontroller(); controller.setmainapp(this); } catch (ioexception e) { // exception gets thrown if fxml file not loaded e.printstacktrace(); } } }
import javafx.concurrent.task; import javafx.fxml.fxml; import javafx.scene.control.checkbox; import javafx.scene.control.textfield; import javafx.scene.layout.anchorpane; import javafx.scene.layout.vbox; import javafx.stage.stage; public class textprocontroller { private mainapp mainapp; // ui controls private autospellingtextarea textbox; @fxml private anchorpane leftpane; @fxml private textfield fleschfield; @fxml private checkbox autocompletebox; @fxml private checkbox spellingbox; @fxml private vbox rightbox; /** * initializes controller class. method automatically called * after fxml file has been loaded. */ @fxml private void initialize() { // make field displaying flesch score read-only fleschfield.seteditable(false); // instantiate , add custom text area textbox = new autospellingtextarea(); textbox.setprefsize(570, 492); textbox.setwraptext(true); textbox.setlayoutx(40); textbox.setlayouty(25); leftpane.getchildren().add(textbox); } /** * called main application give reference itself. * give reference autospellingtextarea * * * @param mainapp */ public void setmainapp(mainapp mainapp) { this.mainapp = mainapp; textbox.setmainapp(mainapp); textbox.setreferences(); } }
i don´t know if understood problem, if want resize pane
may use hgrow
property controls horizontal grow along anchorpane.left/rightanchor
fixes left/right side of pane
parent`s @ desired distance. try basic layout. can adapt code.
<hbox maxheight="1080.0" maxwidth="1980.0" prefheight="400.0" prefwidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.controller"> <children> <vbox prefheight="400.0" prefwidth="402.0" anchorpane.leftanchor="0.0" hbox.hgrow="always"> <children> <textarea prefheight="341.0" prefwidth="368.0" /> <hbox prefheight="100.0" prefwidth="200.0" /> </children> </vbox> <vbox layoutx="402.0" maxwidth="200.0" prefheight="400.0" prefwidth="200.0" anchorpane.rightanchor="0.0" hbox.hgrow="never"> <children> <button mnemonicparsing="false" prefheight="25.0" prefwidth="114.0" text="button"> <vbox.margin> <insets left="50.0" top="50.0" /> </vbox.margin> </button> <button mnemonicparsing="false" prefheight="25.0" prefwidth="117.0" text="button"> <vbox.margin> <insets left="50.0" top="50.0" /> </vbox.margin> </button> <button mnemonicparsing="false" prefheight="25.0" prefwidth="117.0" text="button"> <vbox.margin> <insets left="50.0" top="50.0" /> </vbox.margin> </button> </children> </vbox> </children> </hbox>
Comments
Post a Comment