我創建了一個簡單的GUI,其中有一個TextArea
。 TextArea
本身將由Array
填充,其中包含.txt
文件中已掃描的字符串。在JavaFX中使用大的txt文件(TextArea的替代方案?)
這適用於較小尺寸的文件。但是,當使用大文件(每txt.-file大約5MB)時,TextArea
(以及僅TextArea
)會感覺遲緩且緩慢(不如我想要的那樣快速響應)。是否有替代TextArea
(不必在JavaFX
)?
我在找東西很簡單,基本上可以讓我得到&設置文字。 Slidercontrol
,如JavaFX
TextArea
,將非常方便。
謝謝你,祝你有美好的一天!
編輯:我的代碼一個很簡單的例子:
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();
}
}
最大容量數據控制具有虛擬模式',以提供數據(所需的行)的一部分。但它並不簡單,就像get&set –
您需要創建一個[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve)併發布代碼。 – Sedrick
@SedrickJefferson下面是一個示例,如指南中所述(編輯開始帖子) – Matt