I am using netbeans6.7.1 and phpmyadmin for my db to develop a java application to manage students records i want to upload students photos through browsing by clicking a browse buton which i have included in my interface
I mean when i click on that button a JFilechooser pops up which filter only images(i have acomplished this)
- what i need is when i click on the "Attach button" of the JFilechooser, i want the image i chose to be attached to a jtextArea on the form i'm working with and the JFilechooser be diposed off.
- Also how i can save this form together with the image to a database table
Is there a place whe开发者_JAVA技巧re i can find a good guide/tutorial about that
JFileChooser chooser;
FileNameExtensionFilter filter;
chooser = new JFileChooser();
filter = new FileNameExtensionFilter("jpeg, gif and png files", "jpg", "gif", "png");
chooser.addChoosableFileFilter(filter);
jButton1.addActionListener(this);
if(e.getSource()==jButton1)
{
int i = chooser.showOpenDialog(jPanel1);
if(i==JFileChooser.APPROVE_OPTION)
{
jPanel2.removeAll();
jPanel2.repaint();
File image = chooser.getSelectedFile();
ImageIcon photo = new ImageIcon(image.getAbsolutePath());
//jPanel2.add(new JLabel(photo));
JLabel label=new JLabel("",photo,JLabel.CENTER);
jPanel2.add(label,BorderLayout.CENTER);
jPanel2.repaint();// sets a default image in image field.
jPanel2.revalidate();
}
}
Note:You should set borderlayout for jpanel2 and the selected image size must be the size of jpanel2
精彩评论