javafx , JavaFX Class LineChart zoom operation doesn't work

JavaFX Class LineChart zoom operation doesn't work


Tag: javafx

I have a problem I can not figure out. Please let me put the code first for better explanation:

    public class TestXYChart extends Application {
        NumberAxis xAxis = new NumberAxis();     //     1
        NumberAxis yAxis = new NumberAxis();     //     2
        XYChart.Series series1 = new XYChart.Series();
        public void start(Stage primaryStage) {

        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 250);

        LineChart lineChart = new LineChart<Number, Number>(xAxis, yAxis);

        series1.getData().add(new XYChart.Data(1, 20));
        series1.getData().add(new XYChart.Data(2, 40));
        series1.getData().add(new XYChart.Data(3, 100));
        series1.getData().add(new XYChart.Data(4, 50));
        series1.getData().add(new XYChart.Data(5, 170));
        series1.getData().add(new XYChart.Data(6, 190));
        series1.getData().add(new XYChart.Data(7, 30));
        series1.getData().add(new XYChart.Data(8, 39));
        series1.getData().add(new XYChart.Data(9, 44));
        series1.getData().add(new XYChart.Data(10, 78));
        series1.getData().add(new XYChart.Data(11, 93));
        series1.getData().add(new XYChart.Data(12, 75));

//        this.loadIntoDataBaseFromFile();

        primaryStage.setTitle("Hello World!");

     * @param args the command line arguments
    public static void main(String[] args) {

    EventHandler scrollHandler = new EventHandler<ScrollEvent>(){

        public void handle(ScrollEvent event) {
           System.out.println("Handling Scroll Event");
           xAxis.setLowerBound(xAxis.getLowerBound() + 1);
           xAxis.setUpperBound(xAxis.getUpperBound() - 1);


I use the code above to test whether I can operate the LineChart, especially when I scroll mouse, the LineChart will zoom in/out. I found the fact that exactly as above code, it doesn't work. But if we just change the first two line codes, change from:

    NumberAxis xAxis = new NumberAxis();     //     1
    NumberAxis yAxis = new NumberAxis();     //     2


    NumberAxis xAxis = new NumberAxis(0,12,0.5);     //     1
    NumberAxis yAxis = new NumberAxis(0,300,10);     //     2

Everything works well. So, why it happens like this?Thank you.

And, if I seperate the new NumberAxis(...) instance from the declaration NumberAxis xAxis/yAxis, it doesn't work too.


The difference between using an empty constructor or with arguments is clear if you have a look at NumberAxis JavaDoc:

public NumberAxis() Create a auto-ranging NumberAxis


public NumberAxis(double lowerBound, double upperBound, double tickUnit) Create a non-auto-ranging NumberAxis with the given upper bound, lower bound and tick unit

Basically, the first one has autoRanging set to true, what means it will try to show the data, no matter how you modify the bounds of the axis.

On the contrary, the second one has autoRanging set to false, so any change in the axis bounds will be reflected on the chart.

Note that you can set this in the first case to change the default behaviour:



Javafx TextField pseudoClassStateChanged method not working

I'm setting PseudoClass to TextField to highlight them when error occurs. The red border appears around TextField only when I click mouse inside it (to put text value), but I need to show border all time. there is how I sets border: element.pseudoClassStateChanged(PseudoClass.getPseudoClass("error"), true); It worked just fine till last...

JavaFX subclassed Button - How to make Label update work?

I want to have several JavaFX Buttons that update one Label in my Application with text. For testing purposes it's just Button Text. What I did at first worked fine and looked like this: String Text = "..."; public void kons() { System.out.println("Works..."); System.out.println(Text); Tekst.setText(Text); Button G4 = new Button("Spadantes");...

FXML file won't load even when file path is correct

I am trying to load an FXML file: URL url = getClass().getClassLoader().getResource("/frontEnd/fxml/ModeScreen.fxml"); try { this.value = FXMLLoader.load(url); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } But when I run, I get: NullPointerException: Location is required the path to my fxml file is: src/frontEnd/fxml/ModeScreen.fxml and the path...

How would I connect to a MySQL database back-end from an Android device's application? [closed]

I have developed a standalone JavaFx application in Netbeans with a MySQL database back-end which I want to also package as an APK package for running on Android. How would I go about porting the MySQL database script it uses to Android?

JavaFX: Artifact displays empty window only

Preface: I am pretty new to JavaFX Made an simple image resizing application and need to build an artifact of the application. Using IntelliJ and Eclipse (tried both), i built normal JAR artifacts and JavaFX artifacts. Both are executable, but only show an empty window. When starting the application out...

JavaFX: How can I horizontally center an ImageView inside a ScrollPane?

viewScroll.setContent(new ImageView(bigimg)); double w = viewScroll.getContent().getBoundsInLocal().getWidth(); double vw = viewScroll.getViewportBounds().getWidth(); viewScroll.getContent().setTranslateX((vw/2)-(w/2)); viewScroll.toFront(); I set an ImageView with some Image inside the ScrollPane but the ImageView always goes to the far left corner. Here I'm trying to manually offset the difference, but it doesn't work well. The ImageView goes too far...

JavaFX TextField : Automatically transform text to uppercase

I have a JavaFX TextField control on my FXMl that looks like this... <TextField fx:id="input_search" onKeyPressed="#keyListener" prefHeight="25.0" prefWidth="197.0" /> I want to automatically change all characters to uppercase when the user is typing. The code in my controller : public void keyListener(KeyEvent event){ //maybe transform the pressed key to uppercase...

How is the Point2D “angle” method to be understood?

I thought I'd use the Point2D class for calculating e. g. the angle betwen 2 points instead of creating a utility method. It turned out, it's not usable at all. Code example: Point2D p1; Point2D p2; p1 = new Point2D(0, 0); p2 = new Point2D(10, 10); System.out.println( "Point2D: " +...

java - Is JavaFX SortedList stable?

Let's say I want to sort a list twice, using different comparators each, with the first comparator taking precedence over the second. Is it OK to simply call the SortedList constructor twice, with one call for each comparator? To clarify why I want to do this, let's say I have...

Javafx Tableview dont show data of ObservableList

i have a Problem mit the Tableview in JavaFX. I know there are some other posts in the forum, but i checked them and tried to use the solutions, but nothing work for me ... I have 3 Classes. One Version class, the data model. The Class which populats the...

Opening frame that is under the JavaFX program category

Most of program is using JFrames throughout the application for all the different windows that can appear. However, I have to play an instructional video for the user inside a JFrame. I couldn't find a way to do this, so I had to make a JavaFX program. Is there a...

Filter JDK Bug System by JavaFX

Is there a way (filter settings, etc) to see only JavaFX related bugs in the JDK Bug System? Also, the Reporter names seem to be gone. Now I'm "J. Duke", I guess like everyone else that doesn't have an acount there. So how do I find the bugs I reported?...

How to fill a JavaFX Sphere with two Colors

How can I fill in JavaFX a 3D Sphere with a linear gradient like a 2d Circle? I work with the JavaFX Scene Builder. ...

How to create toolbar with left, center and right sections in javaFX?

I'm trying to create a customized toolbar in javafx. This toolbar should be able to display controls in the center, in the left side and in the right side (three sections) of its surface. The problem is that I have no idea to achive this. I read many hints related...

Add Layouts on TabPane JavaFX

i have a quick question. I want to build an UI with JavaFX. It should have tabs, each with some content. The problem that I have is, I dont know how to arrange the content in the tabs properly. Is there a possibility to add a Layout to the tabs?...

javafx position elements around a central point

Apologies, as this is a rubbishy asked question, but I am totally flumped here about the best approach. I believe there must be something inbuilt or common practice for this but I can't find it and Google has turned up nothing of much value. I have a javafx scene with...

UI4J - Get the entire document innerhtml

Is there a way to get the innerhtml for the entire page, including html, head, body and so on. I am only able to call page.getDocument().getBody().getInnerHTML() ... there is no page.getDocument().getInnerHTML() ... shouldn't there be ?...

FX - Suggestions for aligning CheckBox in Grid

Converting from Swing to FX here. We have some CheckBoxes where the Label appears on the left side of the CheckBox. We are accomplishing this by calling setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); The problem is that in some GridPanes, we'll have a Label in column 0 with a Node in column 1 on row...

Multi-Threading error when binding a StringProperty

I have a question about multi-threading and the binding of a StringProperty. I have a class CacheManager, which contains a Thread which updates my cache with the changes on the server. Now, I want to notify the user with a text and percentage of the progress (which are a Label...

JavaFX FilteredList, filtering based on property of items in the list

I have a case where I need to filter a ObservableList<Item> based on some properties of the items (i.e. the condition is internal and not external). I found out that javafx has FilteredList so I tried it. I could set the predicate and filtering works, until the property value that...

JavaFx TreeCell how to expand nodes after one second

i'm implementing the Drag&Drop on a generic TreeView. My purpose is to expand a folder during DragEntered event after a second of stationing, actual code: setOnDragEntered(e -> { TreeItem<TreeItemContent> enteredItem = getSourceItem(e); if(model.isFolder(enteredItem)){ enteredItem.setGraphic(images.getFolderOpened()); enteredItem.setExpanded(true); } e.consume(); }); desired: setOnDragEntered(e -> { TreeItem<TreeItemContent> enteredItem = getSourceItem(e); if(model.isFolder(enteredItem)){ if(dragDuration >= 1...

How to make a Javafx Image Crop App

I am building an application for my colleagues to crop image. I use FXML with Scene Builder to build the GUI. The user click a button to choose a image from his computer. Then, the image is shown in the GUI. User can zoom and move in the pane. At...

Can I apply 2D transforms to shapes on a JavaFX 8 Canvas?

I'm porting a class that that was previously done in Swing to JavaFX 8. It displays a UI element that looks like an analog electric voltage meter with a half circle surrounded by a collection of "tic marks" at regular intervals. In the Swing version the class was an extension...

What is wrong with this JavaFX/FXML custom component?

I am learning to write FXML custom components for use with JavaFX 8 and Scene Builder. I wrote the FXML file shown below but Scene Builder will not open it, giving me the message "Open operation has failed" due to the exception: javafx.fxml.LoadException: mycustomcomponent.TicoTeco is not a valid type....

JavaFX - How to add Item to ListView from different Stage?

How can i add an item to an already existing ListView from a different Stage (Window). Basically i just want to add Text to the ListView from Window 2 to the ListView in Window 1. Thanks in advance. Sorry i forgot this is what i've got so far in my...

Rotate line segment with Button

I have a line which has points (x1,y1) and (x2,y2). I wanted to attach a Button to it, it should align with the line by rotating based on the line segment points. I need some help in calculating the rotation angle for the Button.

Are JavaFX Property objects threadsafe for multiple asynchronous writes?

Is it dangerous for the standard implementations of Property in JavaFX to call set methods from multiple threads? I don't really care about race conditions on the client side from reading-and-then-setting operations. I want to know if the Property itself can be corrupted internally if multiple threads call its set()...

Applying CSS to JavaFX TextAreas

I want to change the background color of a TextArea using CSS. I'm using this line: -fx-control-inner-background: #00FF99; The problem is that the TextArea only displays this color when it has focus. I know TextAreas are composed of several different Nodes. Do I have to alter another one to make...

JavaFX8 : Single Controller for 1+1popup scene (Solved)

After following the tutorial at, I have a functioning popup window, however, I am having difficulty figuring out how to interact with it with a controller. From the tutorial, I got the impression that there is to be a shared controller between the two FXML files, but I'm having...

Present node +LineChart + JavaFX

I am using LineChart in the javafx8 and I am able to get the series plotted dynamically in the graph and the symbols plotted for every input. But the problem is I just want to show the symbol for the present node and not for the nodes which are already...

JavaFX Input Validation Textfield

I'm using JavaFX and Scene Builder and I have a form with textfields. Three of these textfields are parsed from strings to doubles. I want them to be school marks so they should only be allowed to be between 1.0 and 6.0. The user should not be allowed to write...

JavaFX - how to get background color of Tab, Button, etc

Problem description: I can't get background of object in JavaFX. I don't mean Shapes, but normal Nodes like Buttons, Tabs and others. I don't know how to access to theirs background color. What I want? I am developing IDE and I want to run Color animation on tab with file...

Why JavaFX requires Platform.runLater to change anything in it's UI inside a thread?

This code of a simple swing application: final JFrame jFrame = new JFrame(); final JLabel jLabel = new JLabel("Test"); jFrame.add(jLabel); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.pack(); jFrame.setLocationRelativeTo(null); jFrame.setVisible(true); Thread thread = new Thread(){ @Override public void run() { while(true) { jLabel.setText("Time: " + System.currentTimeMillis()); try { Thread.sleep(1000);} catch(Exception ex) {} } } }; thread.setDaemon(true);...

How to display HTML in JavaFX Application

I am developing a FontViewer application which changes the font of the text based on the selected font style. This is the controller class of my application public class FXMLDocumentController implements Initializable { @FXML private ListView fontListView; @FXML private TextArea fontTextArea; int[] fontSizes = {34, 28, 24, 20, 18, 16,...

Getting a mouse position with JavaFX and Event

I'm trying to get the position of a mouse click in my JavaFX application. I have an EventHandler as so: EventHandler<Event> mouseHandler = new EventHandler<Event>() { @Override public void handle(Event event) { String eType = event.getEventType().toString(); if(eType.equals("MOUSE_PRESSED")){ //mouse position } } }; which is called on mouse press, release and...

How to draw a rectangle over an element on the image using JavaFX?

I have an image which is displayed on my JavaFX application. Given the coordinates, I must display that part on the image using a rectangle. For example, if there is a textfield on the image and I give the coordinates of the textfield, a rectangle should appear over the textfield...

How to analyze incoming message (JavaFX on Android)

I ported my JavaFX application to my Android device. I want my application to read incoming SMS messages and store it in a database. I found several questions here in StackOverflow but I don't know how to implement in a JavaFX approach. Please help!

FXML: ClassNotFoundException

I'm very new to JavaFX and I'm having problem using my custom class in FXML. The console keeps giving me this exception when trying to load main.fxml: ... 1 more Caused by: java.lang.ClassNotFoundException: sample.View$BoardPane at ... I created BoardPane class as a subclass of FlowPane in package sample.View and...

How to change ImageView on KeyPressed

I am having difficulty trying to solve this, I am currently trying to figure out how to change the ImageView to another ImageView when I press a certain Key on my keyboard but I have no idea how to, I have already looked around almost everywhere I can think of...

LayoutY of GridPane not affected by ScrollBar Listener

I have a GridPane that i fill dynamically, then I display it, the problem is: if the rows are so many, then the rows in the bottom don't get displayed, what i want is to add a scrollbar so that I can display all of the rows, here is the...

JavaFX splash screen message and progress not updating

I have a JavaFX application that checks for the presence of a database at startup. If the database is not found, a "seed" database must be created before the program can proceed. Since creating the seed database can be lengthy, I want to display a splash screen and show progress...

How to change the color of treeitem expand and collapse arrow in javafx?

I have got some trouble with treeitems of a treeview. There are expand and collapse icon-arrows, when you have child-treeitems. I only know how to change the background-color of this expand/collapse icons. But I don't know how to change the color of the arrow. .tree-cell .tree-disclosure-node { -fx-background-color: #CCCCCC; }...

Exception when using CheckListView of Controls FX

I have the error : Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index: 0 I thought it was because I have to use Platform.runLater(), but it seems the errors does not come from this. Here's the function that I try to correct with Platform.runLater() : public void setListAirportForFilter(ListAirport listAirport){ this.myListAirport...

Where do I file bugs for JavaFX?

Now that JavaFX Jira Issue Tracker has been moved to JDK Bug System, I don't find an option to file a new bug to the developers. Rather, I find an information saying: Everyone with OpenJDK Author status or above has a JBS account which may be used to create and...

How to accomplish 3 horizontal line menu in fxml

I want to create menu like "Firefox (Three horizontal line - top right side) Menu". I don't know how to create this line of overlay menu in FXML. Have anybody any idea about this? Thank a lot....

JavaFX : Button never sets a graphic

EDIT : A MCVE version of my code has been made to help debug it. It reproduces my bug. The purpose of my code is doing a Memory game. Which means that when it is your turn, you "open" a card, then another one. If they form a pair, they...

compare items of 2 comboboxes

I want to compare the items of 2 comboboxes. Lets say combobox1 has the items ("a", "b", "c", "d") and combobox2 has the items ("b", "c"). I want to check the items and remove them from combobox1 if there is equality. So after comparison combobox1 should have the items ("a",...

Difference between Pane and Group

My question is simple : in JavaFX, what is the difference between a Pane and a Group ? I can't make any difference ... Thank for your answer...

How to identify web actions in JavaFX webview?

I need to catch the actions like clicks, drag, right-click, double click etc, that are done by the user on JavaFX web view. How to achieve it?

Chart JavaFX, my hover Label are hidden by the edges of chart

I have a problem again with the JavaFX Chart : D Context : I had Popup/Label on my chart to display the value on hover : JavaFX LineChart Hover Values (Jewelsea answer) Problem : But when the point are near the edges of chart, the popup is hidden by them....