Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default Refeshing image in JInternalFrame

    Hello everyone,
    I am building a program in which there is refresh the image continuously in JInternalFrame. I have been using timer for continuous updation but the frame is still showing the image captured at the startup of program.
    Please help
    Thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    you may wish to post your code that's doing the refreshing. Most of us are terrible at guessing what your problem is without pertinent code.

  3. #3
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    My code snippet is:
    Java Code:
        public void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    		 Timer timer = new Timer(3000, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
    		String comp =(String)jComboBox1.getSelectedItem();
    	   ImageIcon ii = new ImageIcon(comp+"resized.jpg");
           JLabel lab = new JLabel();
           lab.setIcon(ii);
    
           jInternalFrame1.setTitle(comp); 
           org.jdesktop.layout.GroupLayout jInternalFrame1Layout = new org.jdesktop.layout.GroupLayout(jInternalFrame1.getContentPane());
            jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
            jInternalFrame1Layout.setHorizontalGroup(
                jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 300, Short.MAX_VALUE)
                .add(lab, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 333, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    
            );
            jInternalFrame1Layout.setVerticalGroup(
                jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 240, Short.MAX_VALUE)
    			.add(lab, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    
            );
    
    	  jInternalFrame1.setVisible(true);
          jInternalFrame1.revalidate();
          jInternalFrame1.repaint();
    	  }    
           }); 
    
    		  timer.start();
    	}

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default

    Aw, c'mon. What's your problem, that you don't know what code is pertinent to your problem or that you don't care? You post a whole lot of GroupLayout code that has nothing to do with loading and displaying images, and only one line that IS possibly related to the problem, that too without a hint of what might be contained in the variable "comp" and where and how (and whether) the variable is updated.

    I will say this however: if you're trying to reload the SAME image file (which is concurrently modified by some other means) in your running program, then the behavior you describe is expected, as the ImageIcon constructor that takes a String parameter loads the Image via Toolkit, which caches the image and doesn't load it from disk repeatedly.

    If that guess is correct, you have two options:
    1) Load the image via ImageIO#read and use the ImageIcon constructor that takes an Image
    Java Code:
    Image image = ImageIO.read(new File(comp+"resized.jpg"));
    ImageIcon ii = new ImageIcon(image);
    OR

    2) Invoke the flush() method on the ImageIcon's Image whenever you want it to update from disk.
    Java Code:
    ImageIcon  io = new ImageIcon(comp+"resized.jpg"); // once only
    :
    :
    // to reload the image from disk
    io.getImage().flush();
    In the second case you don't need to setIcon on the label repeatedly, but you may need to invoke repaint().

    I would also recommend that you learn to code your own layouts, relying on a visual designer to do everything for you severely limits what can be done.

    db

  5. #5
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    Thank you very much. Now my code is displaying refreshed image.

  6. #6
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    Hello,
    Now the problem is i am using six of this kind of function in my program.So at a time only one image refreshing in the internal frame and others are not working. Also the layout of whole program disturbs. What should i do?Sometime blank image also appears in frame. I am using another program for updating image in the folder.

  7. #7
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    Can anyone got the solution. Please help.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The main solution is to study the Sun Swing tutorials. You will find them very helpful and will give you the knowledge you need to code Swing or at least know what is the relevant code so you can post it.

Similar Threads

  1. Repositioning An unwanted JInternalFrame
    By marco.c84 in forum AWT / Swing
    Replies: 8
    Last Post: 03-18-2009, 09:42 PM
  2. Problem with JInternalFrame
    By hameem in forum AWT / Swing
    Replies: 1
    Last Post: 12-11-2008, 04:23 PM
  3. setting the view to a jsp page from a self refeshing page
    By deepal_205 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-15-2008, 04:41 PM
  4. [SOLVED] jScrool in JInternalFrame
    By gustio in forum New To Java
    Replies: 2
    Last Post: 07-22-2008, 10:05 AM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 PM

Posting Permissions

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