简体   繁体   English

数字轴无法正确显示javafx

[英]Number axis does not display correctly javafx

For some reasons, I would like to create a lonely Number axis (without any chart) in my javafx application. 由于某些原因,我想在我的javafx应用程序中创建一个孤独的Number轴(无任何图表)。 My problem is that the axis does not seem to expand at all, therefore no value is readable from the axis. 我的问题是该轴似乎根本没有扩展,因此无法从该轴读取任何值。

Here is an exmaple of my problem : 这是我的问题的一个例子:

package application;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();
            NumberAxis axis = new NumberAxis(0, 100, 1);
            axis.setMinWidth(300);
            axis.setPrefWidth(300);
            axis.setMaxWidth(300);
            axis.setLabel("testAxis");
            root.getChildren().add(axis);

            Scene scene = new Scene(root,400,400);

            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Could anyone help me with that ? 有人可以帮我吗?

I assume that an axis without a chart won't work. 我认为没有图表的轴将不起作用。 How about when u just draw your own Axis with a Line and the scale on it? 当您只是用一条线及其比例绘制自己的轴怎么样?

    Pane root = new Pane();

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

    Line lineScal = new Line(0, 50, 600, 50);
    lineScal.setStroke(Color.LIGHTBLUE);
    for (int i = 600; i >= 0; i = i - 50)

    {

        Line line1 = new Line(i, 50, i, 30);

        Text scaleText = new Text(i, 20, Double.toString(i));
        line1.setStroke(Color.LIGHTGRAY);

        root.getChildren().addAll(line1,scaleText);

    }

    root.getChildren().add(lineScal);
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM