Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使文本自动滚动连续循环?_Java_Javafx_Fxml_Autoscroll - Fatal编程技术网

Java 如何使文本自动滚动连续循环?

Java 如何使文本自动滚动连续循环?,java,javafx,fxml,autoscroll,Java,Javafx,Fxml,Autoscroll,我正在寻找一种方法,使用JavaFX使一些文本行自动滚动连续循环。这与下面这些问题的答案非常相似。这是一个工作站屏幕,而不是手机屏幕。文本是固定的,不是来自提要,所以我想让它流传 一个简单的用例:您有30行文本,但在任何时候都只能看到12行。所以我想在屏幕上向上滚动文本,在底部稍作停顿,然后文本环绕并保持滚动 我以为我可以在底部添加文本,然后从顶部移除,结果却不一样。使用向上滚动的视觉效果。。。是规范的重要部分。所以我回到了开始 有些事情我更喜欢的是不需要破坏文本或重新加载。更喜欢指向

我正在寻找一种方法,使用JavaFX使一些文本行自动滚动连续循环。这与下面这些问题的答案非常相似。这是一个工作站屏幕,而不是手机屏幕。文本是固定的,不是来自提要,所以我想让它流传

一个简单的用例:您有30行文本,但在任何时候都只能看到12行。所以我想在屏幕上向上滚动文本,在底部稍作停顿,然后文本环绕并保持滚动

我以为我可以在底部添加文本,然后从顶部移除,结果却不一样。使用向上滚动的视觉效果。。。是规范的重要部分。所以我回到了开始


有些事情我更喜欢的是不需要破坏文本或重新加载。更喜欢指向文本框的当前顶部或其他东西,使其环绕。否则就像以前一样,我需要从顶部删除文本,然后将文本放在底部。需要JavaFX,无法将Javascript用于应用程序。你最拿手的是什么?提前谢谢

这里有一些滚动文本

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Scroll extends Application {

    @Override
    public void start(Stage primaryStage) {
        VBox vbox = new VBox();
        for (int i = 0; i < 30; i++)
            vbox.getChildren().add(new Text("line " + i));
        //add a copy of the first 12 lines that will be showing as wrapped
        for (int i = 0; i < 12; i++)
            vbox.getChildren().add(new Text("line " + i));

        ScrollPane sp = new ScrollPane(vbox);
        Scene scene = new Scene(sp, 300, 10*12);//guess height

        primaryStage.setScene(scene);
        primaryStage.show();
        //resize to exactly 12 lines
        double textHeight = vbox.getHeight() / vbox.getChildren().size();
        primaryStage.setHeight(textHeight*12+primaryStage.getHeight()-scene.getHeight());

        Timeline timeline = new Timeline();
        timeline.setCycleCount(Timeline.INDEFINITE);
        KeyValue kv = new KeyValue(sp.vvalueProperty(), sp.getVmax());
        KeyFrame kf = new KeyFrame(Duration.millis(5000), kv);
        timeline.getKeyFrames().addAll(kf);
        timeline.play();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
导入javafx.animation.KeyFrame;
导入javafx.animation.KeyValue;
导入javafx.animation.Timeline;
导入javafx.application.application;
导入javafx.scene.scene;
导入javafx.scene.control.ScrollPane;
导入javafx.scene.layout.VBox;
导入javafx.scene.text.text;
导入javafx.stage.stage;
导入javafx.util.Duration;
公共类滚动扩展应用程序{
@凌驾
公共无效开始(阶段primaryStage){
VBox VBox=新的VBox();
对于(int i=0;i<30;i++)
添加(新文本(“行”+i));
//添加将显示为已包装的前12行的副本
对于(int i=0;i<12;i++)
添加(新文本(“行”+i));
ScrollPane sp=新的滚动窗格(vbox);
场景=新场景(sp,300,10*12);//猜测高度
初级阶段。场景(场景);
primaryStage.show();
//调整大小,精确到12行
double textHeight=vbox.getHeight()/vbox.getChildren().size();
primaryStage.setHeight(textHeight*12+primaryStage.getHeight()-scene.getHeight());
时间线=新时间线();
timeline.setCycleCount(timeline.unfinite);
KeyValue kv=新的KeyValue(sp.vvalueProperty(),sp.getVmax());
关键帧kf=新关键帧(持续时间.毫秒(5000),千伏);
timeline.getKeyFrames().addAll(kf);
timeline.play();
}
公共静态void main(字符串[]args){
发射(args);
}
}

我意识到这不是你想要的。我尝试了一些技巧来拍摄vbox的图像,并一遍又一遍地播放它,但如果你不正确地使用它,就会出现一些口吃。这只是为了满足只阅读一次文本的要求。你需要的是一个平滑滚动的圆形结构,就像一个圆柱体。看看我的另一个答案吧。

好的,我想我满足了所有的要求,哈哈

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Scroll extends Application {

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

    @Override
    public void start(Stage primaryStage) {

        //a vbox to take a picture of
        VBox vbox = new VBox();
        for (int i = 0; i < 30; i++)
            vbox.getChildren().add(new Text(" longer line of text " + i + " "));

        //take a sideways picture to fit the cylinder
        SnapshotParameters snapshotParameters = new SnapshotParameters();
        snapshotParameters.setTransform(new Rotate(90));
        WritableImage snapshot = vbox.snapshot(snapshotParameters, null);

        //make sideways cyl with image
        PhongMaterial material = new PhongMaterial();
        final Cylinder cylinder = new Cylinder(500, snapshot.getWidth(),30);
        material.setDiffuseMap(snapshot);
        cylinder.setMaterial(material);
        cylinder.setRotate(-90);
        cylinder.setTranslateX(snapshot.getWidth());
        cylinder.setTranslateY(500);

        //lights camera show
        final Group root = new Group();
        root.getChildren().add(cylinder);

        final Scene scene = new Scene(root, snapshot.getWidth()*2, cylinder.getRadius()*2, true);
        PointLight pointLight = new PointLight(Color.ALICEBLUE);
        pointLight.setTranslateX(150);
        pointLight.setTranslateY(500);
        pointLight.setTranslateZ(-1000);
        PerspectiveCamera cam = new PerspectiveCamera(false);
        scene.setCamera(cam);
        root.getChildren().addAll(pointLight, cam);

        primaryStage.setScene(scene);
        primaryStage.show();

        //I'll spin bob 
        Rotate rx = new Rotate();
        rx.setAxis(Rotate.Y_AXIS);
        cylinder.getTransforms().add(rx);
        cam.setRotationAxis(Point3D.ZERO);
        Timeline timeline = new Timeline();
        timeline.setCycleCount(Timeline.INDEFINITE);
        final KeyValue kv = new KeyValue(rx.angleProperty(), -360);
        final KeyFrame kf = new KeyFrame(Duration.millis(10000), kv);
        timeline.getKeyFrames().add(kf);
        timeline.play();
    }
}
导入javafx.animation.KeyFrame;
导入javafx.animation.KeyValue;
导入javafx.animation.Timeline;
导入javafx.application.application;
导入javafx.geometry.Point3D;
导入javafx.scene.Group;
导入javafx.scene.PerspectiveCamera;
导入javafx.scene.PointLight;
导入javafx.scene.scene;
导入javafx.scene.Snapshot参数;
导入javafx.scene.image.WritableImage;
导入javafx.scene.layout.VBox;
导入javafx.scene.paint.Color;
导入javafx.scene.paint.PhongMaterial;
导入javafx.scene.shape.圆柱体;
导入javafx.scene.text.text;
导入javafx.scene.transform.Rotate;
导入javafx.stage.stage;
导入javafx.util.Duration;
公共类滚动扩展应用程序{
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
公共无效开始(阶段primaryStage){
//要拍照的vbox
VBox VBox=新的VBox();
对于(int i=0;i<30;i++)
vbox.getChildren().add(新文本(“长文本行”+i+));
//拍摄一张侧面照片以安装气缸
SnapshotParameters SnapshotParameters=新的SnapshotParameters();
snapshotParameters.setTransform(新旋转(90));
WritableImage snapshot=vbox.snapshot(snapshotParameters,null);
//用图像做侧面的圆柱体
PhongMaterial材质=新的PhongMaterial();
最终圆柱体=新圆柱体(500,snapshot.getWidth(),30);
material.setDiffuseMap(快照);
筒体材料(材料);
气缸。设置旋转(-90);
setTranslateX(snapshot.getWidth());
气缸。setTranslateY(500);
//灯光摄像秀
最终组根=新组();
root.getChildren().add(圆柱体);
最终场景=新场景(根,快照.getWidth()*2,圆柱体.getRadius()*2,true);
PointLight PointLight=新的PointLight(Color.ALICEBLUE);
点光源。setTranslateX(150);
点光源。setTranslateY(500);
点光源。setTranslateZ(-1000);
透视摄像头摄像头=新透视摄像头(错误);
场景。设置摄像机(cam);
root.getChildren().addAll(pointLight,cam);
初级阶段。场景(场景);
primaryStage.show();
//我来旋转鲍勃
旋转rx=新旋转();
rx.设定轴(旋转Y_轴);
圆柱体.getTransforms().add(rx);
凸轮设置旋转轴(点3D.ZERO);
时间线=新时间线();
timeline.setCycleCount(timeline.unfinite);
最终键值kv=新键值(rx.angleProperty(),-360);
最终关键帧kf=新关键帧(持续时间.毫秒(10000),千伏);
timeline.getKeyFrames().add(kf);
timeline.play();
}
}

看起来很漂亮。它必须是文本,不能是可写的图像或图形操作。最终用户非常友好