我有一個字符串“abc”,我希望能夠在名為absencesText 的JTextArea 中顯示該字符串。但每次我嘗試"absencesText.setText(abc)" "List absencesText =absencesText.asList(abc);""absencesText.append(abc);", 我明白了不兼容的類型:java.util.List 無法轉換為 java.lang.String我猜這意味著 String--->TextArea 不正確。無論如何要將字符串顯示到文本區域?完整代碼如下。 public void actionPerformed(ActionEvent Action){ if(Action.getSource()== tagTextField){ System.out.println("Clicked"); String searchObject = tagTextField.getText(); try (Stream<String> stream = Files.lines(Paths.get(searchObject + ".0.txt"))) { List<String> abc = stream.filter(str->str.startsWith("433")) .map(s->s.split("433")[1]).collect(Collectors.toList()); System.out.println(abc); // absencesText.append(abc); // List absencesText = absencesText.asList(abc); } catch (IOException e) { e.printStackTrace(); } }//TagTextField如果重要的話,我也有一個 ScrollPane。
將字符串轉換為 JTextArea
慕碼人8056858
2022-07-20 16:17:17