I created my own chart with x and y axises. I found the present choices of charts did not suite my needs. I have managed to built my chart to my likings and now I would like to add all the components to an object that extends AnchorPane. The end results is that my code compiles with no errors, no runtime errors but I don't see any of my panes that I created. I was wondering what the correct procedure is to extend AnchorPane.
This is the code inside my class that extends Application. Works like a charm:
Vector <String[]> v = new Vector<String[]>();
double highest_high = 0;
double lowest_low = 0;
AnchorPane anchorpane = new AnchorPane();
double xaxisHeight = 20;
double yaxisWidth = 60;
double chartYAdjustment = 40;
double barGap = 3;
double bars = 15;
final Chart chart = new Chart(v, yaxisWidth, xaxisHeight, highest_high, lowest_low, chartYAdjustment, barGap);
final YAxis yaxis = new YAxis(yaxisWidth, highest_high, lowest_low);
final XAxis xaxis = new XAxis(xaxisHeight, barGap, bars);
AnchorPane.setTopAnchor(yaxis, 0.0);
AnchorPane.setRightAnchor(yaxis, 0.0);
AnchorPane.setBottomAnchor(yaxis, 20.0);
AnchorPane.setLeftAnchor(xaxis, 0.0);
AnchorPane.setRightAnchor(xaxis, 60.0);
AnchorPane.setBottomAnchor(xaxis, 0.0);
AnchorPane.setLeftAnchor(chart, 0.0);
AnchorPane.setTopAnchor(chart, 0.0);
AnchorPane.setBottomAnchor(chart, 0.0);
AnchorPane.setRightAnchor(chart, 0.0);
anchorpane.getChildren().addAll(chart, yaxis, xaxis);
Scene s = new Scene(anchorpane, 800, 400, Color.BLACK);
stage.setScene(s);
stage.show();
When I put the code inside a class that extends AnchorPane:
public class Main extends AnchorPane{
public void Main(){
Vector <String[]> v = new Vector<String[]>();
double highest_high = 0;
double lowest_low = 0;
double xaxisHeight = 20;
double yaxisWidth = 60;
double chartYAdjustment = 40;
double barGap = 3;
double bars = 15;
final Chart chart = new Chart(v, yaxisWidth, xaxisHeight, highest_high, lowest_low, chartYAdjustment, barGap);
final YAxis yaxis = new YAxis(yaxisWidth, highest_high, lowest_low);
final XAxis xaxis = new XAxis(xaxisHeight, barGap, bars);
AnchorPane.setTopAnchor(yaxis, 0.0);
AnchorPane.setRightAnchor(yaxis, 0.0);
AnchorPane.setBottomAnchor(yaxis, 20.0);
AnchorPane.setLeftAnchor(xaxis, 0.0);
AnchorPane.setRightAnchor(xaxis, 60.0);
AnchorPane.setBottomAnchor(xaxis, 0.0);
AnchorPane.setLeftAnchor(chart, 0.0);
AnchorPane.setTopAnchor(chart, 0.0);
AnchorPane.setBottomAnchor(chart, 0.0);
AnchorPane.setRightAnchor(chart, 0.0);
getChildren().addAll(chart, yaxis, xaxis);
And then in my class that extends Application I have:
Main main = new Main();
Scene s = new Scene(main, 800, 400, Color.BLACK);
stage.setScene(s);
stage.show();
It only displays a black window.
Figure out what I was doing wrong. I have "void" in my constructor call making a method.