延长不工作时锚

时间:2013-01-23 03:29:17

标签: javafx extend pane

我使用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();

它只显示一个黑色窗口。

1 个答案:

答案 0 :(得分:1)

弄清楚我做错了什么。我在构造函数调用中创建了一个“void”。