I’m new to Java with PHP, HTML, CSS experience. When I try to change the width and height my chart takes up in the window NetBeans gives me the error:
error: setWidth(double) has protected access in Region chart.setWidth(450);
I’ve searched through the javafx docs and found that width/height is bound to region, but I’m not sure what that is in my code, I tried a few things but haven’t found it…
I’m sure this is simple..
thanks in advance, Brad.
package test;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.shape.Rectangle;
public class Test extends Application {
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setScene(new Scene(root,1000,1000));
root.getStylesheets().add("test/Chart.css");
Rectangle rect = new Rectangle(35,70);
rect.setLayoutX(30);
rect.setLayoutY(30);
rect.getStyleClass().add("my-rect");
NumberAxis xAxis = new NumberAxis("X Axis", -24d, 24.0d, 2.0d);
NumberAxis yAxis = new NumberAxis("Y Axis", -24.0d, 24.0d, 1.0d);
ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
new XYChart.Data(0.2, 3.5),
new XYChart.Data(0.7, 4.6),
new XYChart.Data(1.8, 1.7),
new XYChart.Data(2.1, 2.8),
new XYChart.Data(4.0, 2.2),
new XYChart.Data(4.1, 2.6),
new XYChart.Data(4.5, 2.0),
new XYChart.Data(6.0, 3.0),
new XYChart.Data(7.0, 2.0),
new XYChart.Data(7.8, 4.0)
)),
new ScatterChart.Series("Series 2", FXCollections.<ScatterChart.Data>observableArrayList(
new XYChart.Data(6.2,3.0),
new XYChart.Data(6.0,4.0),
new XYChart.Data(5.8,5.0)
))
);
ScatterChart chart = new ScatterChart(xAxis, yAxis, data);
chart.setWidth(450);
chart.setHeight(450);
chart.setLayoutX(250);
chart.setLayoutY(250);
root.getChildren().addAll(chart,rect);
}
@Override public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}
The javadoc of
ScatterChart.getHeight()(which in turn isRegion.getHeight()) saysNamely you can adjust and constraint the size of any chart with: