javafx - Slider above the x axis in a chart? -
i trying implement slider
has xychart
below , supposed slider along values of x-axis. new values y-axis dynamilcally added, chart may grow vertically. that's why decided, has inside scrollpane
. question is:
how can reliably position slider above , same length of x-axis?
have tried bind properties concerning width , position of slider
, numberaxis
in fxml , java. see minimal (not) working (as desired) example below:
mainview.fxml
<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import javafx.scene.chart.*?> <?import javafx.scene.layout.vbox?> <?import javafx.scene.layout.hbox?> <?import javafx.scene.layout.*?> <?import javafx.scene.control.*?> <?import javafx.scene.control.slider?> <vbox fx:id="timebox" prefheight="600" prefwidth="800" maxheight="600" maxwidth="800" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children> <slider fx:id="timeslider" blockincrement="30.0" max="360.0" /> <hbox fx:id="scrollbox" fitwidth="${timebox.width}" vbox.vgrow="always"> <children> <scrollpane fx:id="timescrollpane" fittoheight="true" fittowidth="true" fitwidth="${scrollbox.width}" hbox.hgrow="sometimes"> <content> <linechart fx:id="timechart"> <xaxis> <numberaxis fx:id="timeaxis" minortickcount="1" minorticklength="1.0" side="top" ticklabelgap="30.0" ticklength="1.0" tickunit="1.0" upperbound="360.0" /> </xaxis> <yaxis> <categoryaxis fx:id="appearanceaxis" prefwidth="160.0" side="left" /> </yaxis> </linechart> </content> </scrollpane> </children> </hbox> </children> </vbox>
mainviewcontroller
public class mainviewcontroller implements initializable { @fxml private vbox timebox; @fxml private hbox sliderbox; @fxml private slider timeslider; @fxml private hbox scrollbox; @fxml private scrollpane timescrollpane; @fxml private numberaxis timeaxis; @fxml private categoryaxis appearanceaxis; @fxml private linechart<number, string> timechart; @override public void initialize(url location, resourcebundle resources) { // idea: set same x value, not change timeslider.setlayoutx(timeaxis.getlayoutx()); // idea: bind width, stays longer timeslider.prefwidthproperty().bind(timeaxis.widthproperty()); } }
main.java
import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.stage.stage; import javafx.scene.parent; import javafx.scene.scene; public class main extends application { @override public void start(stage primarystage) { try { fxmlloader loader = new fxmlloader(); loader.setlocation(getclass().getresource("mainview.fxml")); parent root = loader.load(); scene scene = new scene(root,800,600); 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); } }
i know, have tried far not much, don't have idea how fix that. chart meant show start-to-stop time of video file on x-axis , annotations appearance intervals on y-axis. reading this…
Comments
Post a Comment