0
我使用JFileChooser
將圖像從桌面加載到JTextArea
,但是當我從PC加載圖像時,軟件掛起。無法使用Swing將圖像加載到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.");
}
但我使用Netbeans。沒有選項 –
@ Vipul.Johri首先,我會停止使用netbeans表單編輯器並開始手動編寫你的UI,它會更好地理解API,第二,是的 – MadProgrammer