It Is Possible for javax.swing.Icon into java.awt.File? as stream
Good Morning To All!:(handshake):
I thanks for Your help,
In my java code i can brows image and set as Icon on JLable, as per the fallowing code
Code:
private javax.swing.JLabel pto;
Image image = null;
private ImageIcon ImageIcon;
private Icon img;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
FileInputStream fin = null;
try {
JFileChooser file_chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG, GIF, & PNG Images", "jpg", "gif", "png");
file_chooser.setFileFilter(filter);
int users_value = file_chooser.showOpenDialog(file_chooser);
if (users_value == JFileChooser.APPROVE_OPTION) {
File img = file_chooser.getSelectedFile();
fin = new FileInputStream(img);
image = ImageIO.read(fin);
ImageIcon =new ImageIcon(image);
pto.setIcon(ImageIcon);
pto.setSize(ImageIcon.getIconHeight(),ImageIcon.getIconWidth());
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);//"Please Enter Valid ID.");
}
}
I wants to store the Icon into MySQL database from the JLabel
But Icon/Images can stored as (Blob) in MySQL,
i have to convert as FIle
like
This is my previous code for brows image and store in MySQL database
Code:
FileInputStream fin = null;
JFileChooser file_chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG, GIF, & PNG Images", "jpg", "gif", "png");
file_chooser.setFileFilter(filter);
int users_value = file_chooser.showOpenDialog(file_chooser);
if (users_value == JFileChooser.APPROVE_OPTION) {
File img = file_chooser.getSelectedFile();
fin = new FileInputStream(img);
Class.forName("com.mysql.jdbc.Driver");
Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip", "root", "root");
PreparedStatement ps = conn.prepareStatement("insert into newemp (Photo) values(?)");
ps.setBinaryStream(1, fin, (int) img.length());
i wants to replace the input, instead of select the image from JFileChooser() into get the icon from JLabel.
Any one can guide me, I am waiting for you response please..,
Thank you..,
Re: It Is Possible for javax.swing.Icon into java.awt.File? as stream
Can Anyone Guide me please..,
Re: It Is Possible for javax.swing.Icon into java.awt.File? as stream