Java Can';t使用Swing将图像加载到JTextArea

Java Can';t使用Swing将图像加载到JTextArea,java,image,swing,jtextarea,Java,Image,Swing,Jtextarea,我正在使用JFileChooser将图像从桌面加载到JTextArea中,但当我从PC加载图像时,软件挂起 以下是文件选择器的OpenActionPerformed方法的代码 private void OpenActionPerformed(java.awt.event.ActionEvent evt) { int returnVal = fileChooser.showOpenDialog(this); if (

我正在使用
JFileChooser
将图像从桌面加载到
JTextArea
中,但当我从PC加载图像时,软件挂起

以下是文件选择器的
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.");
}

JTextArea用于文本而不是图像

如果要显示图像,请将
ImageIcon
添加到
JLabel
并将标签添加到
JFrame


有关读取图像和显示图标的更多信息,请阅读上Swing教程的部分。

但我使用的是Netbeans。没有其他选择that@Vipul.Johri首先,我会停止使用netbeans表单编辑器,开始手工编写UI,它会更好地欣赏API,其次,是的,它会