Я создал свою собственную диаграмму с осями x и y. Я обнаружил, что текущий выбор диаграмм не соответствует моим потребностям. Мне удалось построить свою диаграмму по своему вкусу, и теперь я хотел бы добавить все компоненты в объект, расширяющий AnchorPane. Конечным результатом является то, что мой код компилируется без ошибок, без ошибок времени выполнения, но я не вижу ни одной из созданных мною панелей. Мне было интересно, какова правильная процедура расширения AnchorPane.
Это код внутри моего класса, который расширяет Application. Работает как шарм:
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();
Когда я помещаю код в класс, расширяющий 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);
И затем в моем классе, который расширяет приложение, у меня есть:
Main main = new Main();
Scene s = new Scene(main, 800, 400, Color.BLACK);
stage.setScene(s);
stage.show();
Он показывает только черное окно.