2016-07-28 4 views
0

IDカード処理アプリをJavaで作成していますが、画像用に作成したラベルにクライアント画像をアップロードして表示するコードに問題があります。以下のコードで唯一得られるのは画像パスですが、画像自体ではありません。コードnetbeansを使用してフォームに画像をアップロードする方法

これは私が今まで試みたコードです。

FileFilter ff = new FileNameExtensionFilter("images","jpeg"); 
     fc.addChoosableFileFilter(ff); 
     int open = fc.showOpenDialog(this); 

     if (open == javax.swing.JFileChooser.APPROVE_OPTION){ 

      java.io.File path = fc.getSelectedFile(); 

      String file_name = path.toString(); 

      pathe.setText(file_name); 

      java.io.File image = fc.getSelectedFile(); 

      ImageIcon photo = new ImageIcon(image.getAbsolutePath()); 
+0

これまで –

+0

上記のコードは、私がこれまで持っていると、本当にあなたの助けを必要とするものであるあなたが試みられてきたコードを入力してください。ありがとう –

答えて

0
The code that does the magic is below 

     FileFilter ff = new FileNameExtensionFilter("images","jpeg"); 
     fc.addChoosableFileFilter(ff); 
     int open = fc.showOpenDialog(this); 

     if (open == javax.swing.JFileChooser.APPROVE_OPTION){ 

      java.io.File path = fc.getSelectedFile(); 

      String file_name = path.toString(); 

      pathe.setText(file_name); 

      BufferedImage bi; // bi is the object of the class BufferedImage 
// Now you use try and catch `enter code here` 

try{ 
bi = ImageIO.read(path); // path is your file or image path 
jlabel.setIcon(new ImageIcon(bi)); 
}catch(IOException e){ } 
関連する問題