java在JavaFX中使用大型txt文件(TextArea替代方案?)
我创建了一个简单的GUI,其中有一个TextArea
。TextArea
本身将由一个Array
填充,其中包含.txt
文件中的扫描字符串
这对较小的文件非常有效。然而,当使用大文件(每个txt.-file大约5MB)时,TextArea
(而且只有TextArea
)会感觉迟钝和缓慢(没有我想要的那么灵敏)。除了TextArea
(不必在JavaFX
)之外,还有其他选择吗
我正在寻找一些非常简单的东西,基本上可以让我得到&;设置文本Slidercontrol
和{
谢谢你,祝你今天愉快
编辑:我的代码的一个非常基本的例子:
public class Main extends Application {
public void start(Stage stage) {
Pane pane = new Pane();
TextField filePath = new TextField("Filepath goes in here...");
TextArea file = new TextArea("Imported file strings go here...");
file.relocate(0, 60);
Button btnImport = new Button("Import file");
btnImport.relocate(0, 30);
ArrayList<String> data = new ArrayList<>();
btnImport.setOnAction(e -> {
File fileToImport = new File(filePath.getText());
try {
Scanner scanner = new Scanner(fileToImport);
while(scanner.hasNextLine()) {
data.add(scanner.nextLine());
}
file.setText(data.toString());
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
});
pane.getChildren().addAll(filePath, file, btnImport);
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args){
launch();
}
}
共 (0) 个答案