Results 1 to 3 of 3
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is online now Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Question It Is Possible for javax.swing.Icon into java.awt.File? as stream

    Good Morning To All!

    I thanks for Your help,

    In my java code i can brows image and set as Icon on JLable, as per the fallowing code

    Java 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

    Java 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..,
    Last edited by DarrylBurke; 05-16-2012 at 08:31 AM. Reason: Removed annoying green font

  2. #2
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is online now Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Re: It Is Possible for javax.swing.Icon into java.awt.File? as stream

    Can Anyone Guide me please..,

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: It Is Possible for javax.swing.Icon into java.awt.File? as stream

    This post will do what you want I believe: [SOLVED] Image to byte[]

Similar Threads

  1. java.awt.TrayIcon & javax.swing.JPopupMenu
    By Seyed in forum AWT / Swing
    Replies: 0
    Last Post: 03-18-2011, 07:58 PM
  2. Replies: 33
    Last Post: 09-06-2010, 10:49 PM
  3. Replies: 6
    Last Post: 05-27-2009, 01:17 AM
  4. Replies: 6
    Last Post: 07-10-2008, 07:28 PM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •