首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TextArea setScrollTop

TextArea setScrollTop
EN

Stack Overflow用户
提问于 2014-05-06 13:41:25
回答 1查看 1.3K关注 0票数 1

我创建了这个简单的TextArea示例

代码语言:javascript
复制
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class MainApp extends Application
{

    @Override
    public void start(Stage stage) throws Exception
    {

        HBox hbox = new HBox();
        // Text Area
        TextArea dataPane = new TextArea();
        dataPane.setScrollTop(0);
        dataPane.setEditable(false);
        dataPane.prefWidthProperty().bind(hbox.widthProperty());

        dataPane.setWrapText(true);     // New line of the text exceeds the text area
        dataPane.setPrefRowCount(10);
        dataPane.appendText("Computer software, or simply software, also known as computer programs");
        dataPane.appendText("\nis the non-tangible component of computers.");
        dataPane.appendText("\nComputer software contrasts with computer hardware, which");
        dataPane.appendText("\nis the physical component of computers.");
        dataPane.appendText("Computer hardware and software require each");
        dataPane.appendText("\nother and neither can be");
        dataPane.appendText("\nrealistically used without the other.");
        dataPane.appendText("\nComputer software");

        hbox.setAlignment(Pos.CENTER);
        hbox.setSpacing(1);
        hbox.setPadding(new Insets(10, 0, 10, 0));
        hbox.getChildren().add(dataPane);

        Scene scene = new Scene(hbox, 800, 90);

        stage.setTitle("JavaFX and Maven");
        stage.setScene(scene);
        stage.show();
    }

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

}

默认情况下,我希望将滑块的位置设置为TextArea的顶部。你能帮我修一下吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-06 13:58:27

如果您在舞台显示后设置了dataPane.setScrollTop(0);,它将工作:)

就像这样:

代码语言:javascript
复制
@Override
public void start(Stage stage) {
    HBox hbox = new HBox();
    // Text Area
    TextArea dataPane = new TextArea();

    dataPane.setEditable(false);
    dataPane.prefWidthProperty().bind(hbox.widthProperty());

    dataPane.setWrapText(true);     // New line of the text exceeds the text area
    dataPane.setPrefRowCount(10);
    dataPane.appendText("Computer software, or simply software, also known as computer programs");
    dataPane.appendText("\nis the non-tangible component of computers.");
    dataPane.appendText("\nComputer software contrasts with computer hardware, which");
    dataPane.appendText("\nis the physical component of computers.");
    dataPane.appendText("Computer hardware and software require each");
    dataPane.appendText("\nother and neither can be");
    dataPane.appendText("\nrealistically used without the other.");
    dataPane.appendText("\nComputer software");

    hbox.setAlignment(Pos.CENTER);
    hbox.setSpacing(1);
    hbox.setPadding(new Insets(10, 0, 10, 0));
    hbox.getChildren().add(dataPane);

    Scene scene = new Scene(hbox, 800, 90);

    stage.setTitle("JavaFX and Maven");
    stage.setScene(scene);
    stage.show();

    dataPane.setScrollTop(0.0); 
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23496394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档