1
我創建文本區文本區域setScrollTop
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的頂部的這個簡單的例子。 你能幫我解決這個問題嗎?