2017-04-07 1 views
0

JFileChooser을 사용하여 데스크탑에서 이미지를 JTextArea으로로드하지만 PC에서 이미지를로드하면 소프트웨어가 중지됩니다.스윙을 사용하여 JTextArea로 이미지를로드 할 수 없습니다.

다음은 파일 선택기의 OpenActionPerformed 메소드 코드입니다.

private void OpenActionPerformed(java.awt.event.ActionEvent evt) {          
    int returnVal = fileChooser.showOpenDialog(this); 
if (returnVal == fileChooser.APPROVE_OPTION) { 
    File file = fileChooser.getSelectedFile(); 
    try { 
     // What to do with the file, e.g. display it in a TextArea 
     textarea.read(new FileReader(file.getAbsolutePath()), null); 

    } catch (IOException ex) { 
     System.out.println("problem accessing file"+file.getAbsolutePath()); 
    } 
} else { 
    System.out.println("File access cancelled by user."); 
} 

답변

1

JTextArea는 이미지 용 텍스트가 아닙니다.

이미지를 표시하려면 ImageIconJLabel에 추가하고 JFrame에 레이블을 추가하십시오.

이미지 읽기 및 아이콘 표시에 대한 자세한 내용은 How to Use Icons의 스윙 튜토리얼의 섹션을 참조하십시오.

+0

하지만 Netbeans를 사용하고 있습니다. 거기에 대한 옵션이 없습니다 –

+1

@ Vipul.Johri 첫째, 나는 netbeans 양식 편집기를 사용하여 중지하고 귀하의 UI를 코딩 손 시작, 그것은 API에 대한 더 나은 감사를 줄거야 두 번째 예, 그렇지 않습니다 – MadProgrammer

관련 문제