JEditorPane Docs를 통해 읽었습니다. editorpane.setText (String value); 그러나 나는 Java에 매우 익숙하며이 솔루션은 내 코드에서 작동하지 않습니다. 나는 명백한 아이디어를 완전히 잃어 버렸다고 생각한다.JEditorPane - ArrayList로부터 setText를 <String> 내용?
JEditorPane을 확장하는이 클래스로 새 탭을 만들었습니다.이 클래스는 파일의 내용을 열고 배열에 배치하고 배열을 뒤집어서 (최신 항목이 맨 위에 있음) 다음을 표시합니다. 나는 행운와의 setText() 괄호에 여러 다른 항목을 시도
public class HistoryPane extends JEditorPane{
ArrayList<String> historyToSort = new ArrayList<String>();
public HistoryPane(){
setEditable(false);
historySort();
}
public void historySort() {
try (BufferedReader reader = new BufferedReader(new FileReader("BrowserHistory.txt")))
{
String currentLine;
String newLine = new String("\n");
while ((currentLine = reader.readLine()) != null) {
historyToSort.add(currentLine + newLine);
}
} catch (IOException e) {
e.printStackTrace();
}
Collections.reverse(historyToSort);
System.out.println(historyToSort);
}
{
}
private void displayHistory(){
String sorted = historyToSort.toString();
***** HistoryPane.setText(String sorted); <<<------ PROBLEM SYNTAX.*****
}
}
JEditorPane의의 목록은, (I 하이퍼 링크로 저장하는 URL의 할 필요가 있기 때문에 JEditorPane로 사용). 내가 뭘 놓치고 있니? 고맙습니다.
참고 :
이 (내가 모두를 붙여 넣을 수 없습니다) 다른 클래스에 의존하지만이 코드는 내 메인 클래스에 의해 생성 된 탭 구획 내에 자리 잡고 있기 때문에이 클래스는 컴파일되지 않습니다 :
오류 메시지 :
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: Syntax error on token "setText", Identifier expected after this token Return type for the method is missing This method requires a body instead of a semicolon
작동하지 않는 기능은 무엇입니까? 이 코드가 기대하는 것은 무엇이며, 대신 무엇을합니까? –
어디에서'setText()'를 호출합니까? – ApproachingDarknessFish
죄송합니다. 필자는 코드에서 편집자의 화면에 내 배열 (파일의 기록 행)을 표시 할 것으로 예상했습니다. 나는 맨 아래에 "HistoryPane.setText (String sorted);"라고 부른다. 또는 그래서 나는 생각 ... 나는 JEditorPane에 표시된 텍스트를 설정할 것이라고 생각했다. 문제는 IDE에서 setText()에 STRING 및 Value를 받아들이지 않는다는 오류가 발생하는 것입니다.어느 것도 유효하지 않은 제안을 제시합니다. –