Image Refresh In JDesktopPane or JFrame

I have a project that I'm doing as a side thing in one of my computer science classes. I'm coding a Net Control program that allows me to control a computer running my server. All the command and mouse listeners work perfectly, but I'm having trouble getting the desktop from one computer onto another. Whenever the computer being controlled executes a command, it gets a screenshot of itself and saves it to a shared network file as a .jpg. My control program then goes to the shared file, loads the image and draws it on the screen using paintComponent. I can get the initial image, but the image does not refresh. I've looked at the image file and the file itself is updating. So I think my problem lies in my control program just not refreshing the image. Here's the code for my paintComponent:
private String path = "\\\\School\\be111lab\\HANOSH2ND\\All Class\\ConsoleNetChatServer\\classes\\";
public void paintComponent(Graphics g)
    Graphics2D g2d = (Graphics2D)g;
    g2d.drawImage(new ImageIcon(path + "screen.jpg").getImage(),null,null);
}That was one of the things I tried. Another thing that I tried was using a JLabel and then changing the image with the following code.
label.setIcon(new ImageIcon(path + "screen.jpg"));This has also not been working. Someone on another forum told me to try the swing forums for refreshing background images. Hopefully someone out there knows how to fix this.

I've never tried it but it sounds like
Toolkit.createImage(...)
won't have a problem with caching.

Similar Messages

  • Image in a JDesktopPane background

    Is it possible to paint an Image in a JDesktopPane background ??
    how can I get it ?

    take the ImageIcon containing the image and add it to a JLabel.
    ex:
    ImageIcon icon = new ImageIcon("yourImage.?")
    JLabel label = new JLabel(icon)
    Next take the label and stick it to a lower level the pane containing your components.
    ex:
    (yourJPane).getLayeredPane().add(label, new Integer(Integer.MIN_VALUE))
    also make sure the JLabel is the size of the image.
    ex:
    label.setBounds(0, 0, yourImage.getIconHeight(), yourImage.getIconWidth());
    make sure your panel is non-opaque and it should work
    ex:
    ((JPanel)getContentPane()).setOpaque(false);
    I may not have the code examples exactly right but your answer does lay in the JLayeredPane realm.
    -d

  • Need help with Image refreshing using the 1408

    I'm trying to develop a VI that allows user control over the image refreshing. In the end I would like something that allows the user to view a live or somewhat close to live image from the camera, and then when they desire freeze the image. The catch is I would also like the images to be color, and to allow the user to again view a live image if they wish.
    Essentially I want the user to be able to focus the camera and set light levels while viewing a live image on the screen (again flicker is ok, just as long as it has a decent refresh rate). And then when ready freeze the image and use the last image captured (the frozen one) for some analysis purposes.

    The simplest way to do this is to put the IMAQ Snap vi inside a while loop. Initialize your image and IMAQ outside the loop. Create an "Acquire" boolean control on your front panel. Put the Snap & display inside a case statement so that it only acquires a new image if the Acquire button is in the "On" position. This will give you a pretty smooth update rate and is very easy to program.
    If you want an update rate closer to the frame rate of the camera, you can set up an IMAQ Grab outside the loop, then read the latest image and display it in the case statement.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • Adding Canvas3D image to a JPanel or JFrame

    My team has developed a 3D game board and we want to add it to a JPanel. The test code below works fine but we want to add this to a JPanel. Can you put a Canvas3D in a JPanel?
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Frame;
    import java.awt.event.*;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import java.awt.event.*;
    import java.util.Enumeration;
    import com.sun.j3d.utils.behaviors.mouse.*;
    import com.sun.j3d.utils.behaviors.keyboard.*;
    public class ProxyBoard extends Applet
         public class SimpleBehave extends Behavior
              private TransformGroup targetTG;
              private Transform3D rotation = new Transform3D();
              private double angle = 0.0;
              SimpleBehave(TransformGroup targetTG)
                   this.targetTG = targetTG;
              public void initialize()
                   this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
              public void processStimulus(Enumeration criteria)
                   angle +=0.05;
                   rotation.rotX(angle);
                   targetTG.setTransform(rotation);
                   this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
         public ProxyBoard()
              setLayout(new BorderLayout());
              Canvas3D canvas3D = new Canvas3D(null);
              add("Center", canvas3D);
              SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
              simpleU.getViewingPlatform().setNominalViewingTransform();
              BranchGroup scene = createSceneGraph(simpleU);
              scene.compile();
              simpleU.addBranchGraph(scene);
         public BranchGroup createSceneGraph(SimpleUniverse su)
              BranchGroup boardBG = new BranchGroup();
              TransformGroup vpTrans = null;
              BoundingSphere mouseBounds = null;
              vpTrans = su.getViewingPlatform().getViewPlatformTransform();
              mouseBounds = new BoundingSphere(new Point3d(), 1000.0);
              KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
              keyNavBeh.setSchedulingBounds(mouseBounds);
              boardBG.addChild(keyNavBeh);
              MouseRotate myMouseRotate = new MouseRotate(MouseBehavior.INVERT_INPUT);
              myMouseRotate.setTransformGroup(vpTrans);
              myMouseRotate.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseRotate);
              MouseTranslate myMouseTranslate = new MouseTranslate(MouseBehavior.INVERT_INPUT);
              myMouseTranslate.setTransformGroup(vpTrans);
              myMouseTranslate.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseTranslate);
              MouseZoom myMouseZoom = new MouseZoom(MouseBehavior.INVERT_INPUT);
              myMouseZoom.setTransformGroup(vpTrans);
              myMouseZoom.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseZoom);
              Board board = new Board();
              Transform3D pegPositions[] = new Transform3D[8];
              TransformGroup pegPositionsTG[] = new TransformGroup[8];
              Pegs pegs[] = new Pegs[8];
              Transform3D translate = new Transform3D();
              translate.set(new Vector3f(0.0f, -1.0f, -5.0f));
              TransformGroup boardTGT1 = new TransformGroup(translate);
              TransformGroup boardTGR1 = new TransformGroup();
              boardTGR1.setCapability(boardTGR1.ALLOW_TRANSFORM_WRITE);
              for(int i = 0; i < 8; i++)
                   pegs[i] = new Pegs();
                   pegPositions[i] = new Transform3D();
                   pegPositions.set(new Vector3f(-2.5f, 0, (float)(-i/4.0)));
                   pegPositionsTG[i] = new TransformGroup(pegPositions[i]);
                   pegPositionsTG[i].addChild(pegs[i].getTransformGroup());
                   boardTGT1.addChild(pegPositionsTG[i]);               
              boardTGR1.addChild(board.getBoard());
              SimpleBehave myRotate = new SimpleBehave(boardTGR1);
              myRotate.setSchedulingBounds(new BoundingSphere());
              boardBG.addChild(myRotate);
              boardTGT1.addChild(boardTGR1);
              boardBG.addChild(boardTGT1);                    
              boardBG.compile();
              return boardBG;
         public static void main(String[] args)
              Frame frame = new MainFrame(new ProxyBoard(), 800, 600);
    /*-------------Main Source Container------------------*/
    public class Proxy extends JFrame
         implements MouseMotionListener
         private JDesktopPane myDesktop;
         private JPanel panel;
         private JLabel statusBar, position;
         private JSlider zSlide, zSlide1;
         private ImageIcon test;
         private int i;
         public Proxy()
              super("Proxy Board Prototype 1.2.2");
              i=0;
              statusBar = new JLabel();
              getContentPane();
              myDesktop = new JDesktopPane();
              getContentPane().add(myDesktop);
    public static void main(String args[])
              Proxy app = new Proxy();
              //new MainFrame( new Proxy(), 800, 600 );
    //          app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    /*-------------JPanel I want to hold to the 3D Graphics--------*/
    class Session extends JPanel
         implements MouseMotionListener
         private ImageIcon test;
         private JLabel position;
         private JSlider zSlide;
         private JPanel panel, gPanel;
         static int openFrameCount = 0;
         public Session()
              //super("", true, true, true, true);
              setLayout(new FlowLayout());
              openFrameCount++;
         //setTitle("Untitled Message " + openFrameCount);
    ProxyBoard pb = new ProxyBoard();//<-Graphic Class
    gPanel = new JPanel();
    gPanel.add(pb);//<-I want the 3D Graphic here
              test = new ImageIcon("Layout.jpg");
              JLabel pic = new JLabel(test);
              addMouseMotionListener( this );
              zSlide = new JSlider(SwingConstants.VERTICAL, 600, 10);
              zSlide.setMajorTickSpacing(25);
              zSlide.setPaintTicks(true);
              zSlide.setToolTipText("Zoom");
              panel.add(zSlide, BorderLayout.NORTH);
              panel.add(gPanel, BorderLayout.CENTER);//<-Graphic Here
              panel.add(position, BorderLayout.SOUTH);
              add(panel);
              //pack();
              setSize(200,200);
              setVisible (true);

    Yes you can. Just use the add method of JPanel. However note this
    http://www.j3d.org/faq/swing.html (specially read this: http://java.sun.com/products/jfc/tsc/articles/mixing/)
    when mixing Lightweight (JPanel) and Heavyweight (Canvas3D) components.

  • Image refreshing on a frame

    the project deals with images which have to be displayed on to a frame, however the images are
    not displayed properly.Initially only a band of the image is displayed... however on trying to resize the frame the image is entirely visible.
    Also we would like to know that in case of using split panes in order to display 2 images at a time
    how do we refresh only one of the panes.

    I have had a similar problem with an image only partially appearing in a Frame. The problem is that the image is not completely loaded when it is displayed. You may have to use a Media Tracker and/or a BufferedImage. I have used the Tracker which eliminates the problem but can cause delays to an image rotation. Another solution would be to use an OffScreenImage to have it preloaded. I think a friend of mine used that in a game we did for comp class last year. If you want the tracker code I used just send me an email and I'll locate it... Good luck with your project....
    Scott

  • How to change the image in title bar for JFrames

    plz give me a small code to change the image of the JFrame in the Title bar.
    i know how to change the name of the title bar .
    import javax.swing.*;
    class Rathna1 extends JFrame
    Rathna1()
    super("rathna project ");
    public class Rathna
    public static void main(String ax[])throws Exception
    Rathna1 r=new Rathna1();
    r.setVisible(true);
    r.setSize(400,400);
    Like this how to change the image of the title bar
    Message was edited by:
    therathna

    hi,
    JFrame frame;
    frame.setVisible(true);
    frame.setIconImage(new ImageIcon("icons/img007.gif").getImage());
    frame.setSize(800,600);
    i think the thing u r searching is :
    frame.setIconImage(new ImageIcon("icons/img007.gif").getImage());
    ~~~radha

  • Wrong image refresh in java applet AND Windows 7

    I'm managing since few days a java applet that takes an image from an industrial product and shows it in a browser (simple web server).
    There is following issue: the image is not correctly loaded and refreshed in its own window if just opened but only if the applet is running on Windows 7. The issue is solved as soon as I reduce the window to icon (minimize) and then resize it. I'm looking into java documentation on how to manage the image rendering, maybe I have to override some update or redraw method more, but it is taking time and I'm still learning. NOTE that the window opened does show the issue only when the windows size is not completely shown in the monitor.
    Meanwhile I'm wandering if some of you faced and solved similar problem.
    Thank you in advance,
    Elena

    Thank you Nitin for your quick reply!
    These are the calling of the functions in the code. As you can see, before to show the image, we are managing a zoom/unzoom by mouse wheel and an addition of writings data on the image itself. All is working fine except on W7:
    public void paint(Graphics g)
         //System.out.println("[ImageFrame::paint my paint!!!]");
         this.PaintImage(g);
    public void update(Graphics g)
         // System.out.println("[ImageFrame::update]");
         this.repaint();
    public void PaintImage(ImageInfo imageInfo, float fps)
         if (imageInfo != null)
              if (this.getImageInfoRef() == null){
                   this.setVisible(true);
              this.setTitle("Image Viewer (" + imageInfo.bufferedImage.getWidth() + "x" + imageInfo.bufferedImage.getHeight() + ") ");
              this.resizeImageFrame((int) (imageInfo.bufferedImage.getWidth() * zoomFactor), (int) (imageInfo.bufferedImage.getHeight() * zoomFactor));
              this.lastFps = fps;
              this.setImageInfoRef(imageInfo);
              //System.out.println("this.getWidth(): " + this.getWidth() + " this.getHeight(): " + this.getHeight() + " zoomFactor: " + zoomFactor);////
              this.PaintImage(this.getGraphics());
    public synchronized void PaintImage(Graphics g)
         ImageInfo locImageInfo = getImageInfoRef();
         if (locImageInfo != null)
              try
                   this.resizeImageFrame((int) (locImageInfo.bufferedImage.getWidth() * zoomFactor), (int) (locImageInfo.bufferedImage.getHeight() * zoomFactor));
                   BufferedImage bufferedImage = this.resizeBufferedImage(locImageInfo.bufferedImage, zoomFactor);
                   this.overlayCodeInfo(bufferedImage, locImageInfo.decInfoStruct, zoomFactor);
                   this.overlayPointerInfo(bufferedImage, locImageInfo.scaling, zoomFactor, this.crossX, this.crossY);
                   this.overlayFrameRateInfo(bufferedImage, this.lastFps);
                   Image img = Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
                   boolean retdraw;
                   retdraw = g.drawImage(img, frameUpperBondarySizeX, frameUpperBondarySizeY, this);
              catch (Exception ex)
                   System.out.println("[ImageFrame::PaintImage] Exception: " + ex);
    Thank you again
    Elena

  • Css background image refresh

    Hi,
    I am using Edge inspect on my mac and pushing it towards an ipad and iphone.
    I did make a css change involving a background image.
    It seems like the image is not getting changed in the refresh by edge on both mobile devices. The whole name is changed not a replace on the server.
    It's similar to a cache problem when developping on a browser.
    Is there a way/setting to resolve this?
    my best.
    Brian

    Thanks Mark.
    After writing on the forum I did find the force refresh button in the extension. It did the trick in updating the images in the background-image css.
    I did also make some change in the html from which the css was being called and it didn't change on the chrome browser refresh. Only worked from the extension force refresh.
    Cheers,

  • SVG image refresh

    Hi,
       I'm saving the SVG images(converted to jpg) in a folder on the server. But I'm not able to refresh the image without refreshing the page.
    DO I need an applet for the page to refresh the image or there's some code... please help....
    Thanks in advance

    Thumb rule before posting : <b>Search before you post</b>
    Check out this thread : xMII page refresh

  • Syslinux on USB not booting Netboot install image (refreshing menu)

    I have installed syslinux on a USB thumb drive. It appears to work except when I add the entry for netboot image as seen on site, syslinux appears to just refresh ...
    LABEL archnetboot
    MENU LABEL Arch Linux Netboot Environment
    KERNEL /ipxe_text.lkrn
    I believe this used to work. Or at least from what I remember I also just copied and paste in the past and it works.

    jiewmeng wrote:
    I have installed syslinux on a USB thumb drive. It appears to work except when I add the entry for netboot image as seen on site, syslinux appears to just refresh ...
    LABEL archnetboot
    MENU LABEL Arch Linux Netboot Environment
    KERNEL /ipxe_text.lkrn
    I believe this used to work. Or at least from what I remember I also just copied and paste in the past and it works.
    It worked and it is also described to be working here: https://releng.archlinux.org/pxeboot/
    However...... For me it is not working anymore either. It seems to fail since the update to syslinux 6.x
    Does anyone have an idea how it would be able to fix this so I can boot my VPS system on the remote PXE server like I used to ?

  • Windows form background image refresh.

    Hi, I am assigning a different background image to the windows control.  The update does not seem to have any effect after the assignment.  Even after refresh or form invalidate statement.  Any aideas?  I am using vb 2010

    Hi, I am assigning a different background image to the windows control.  The update does not seem to have any effect after the assignment.  Even after refresh or form invalidate statement.  Any aideas?  I am using vb 2010
    Which windows control? Is this a WPF project or Windows.Forms project or something else? Unless the image is being drawn then Refresh or Invalidate should not be required.
    Windows.Forms PictureBox.
    PictureBox1.BackgroundImageLayout = Stretch (or whatever precedes stretch too).
    PictureBox1.BackgroundImage = (a bitmap or Image.FromFile("Some path/Some filename.File extension") or something similar).
    or
    PictureBox1.Image = (like the above but the PictureBox probably needs to be sized to the size of the image first or not).
    As
    tommytwotrain says you're making us guess and wasting our time because you don't provide enough information on what your code is doing. Even if you describe it that doesn't mean the code is written correctly.
    La vida loca

  • Image refresh problem

    hi, i have an image inside an iframe that i'm trying to
    change upon the click of a button. i use the following code:
    <SCRIPT language="JavaScript" type="text/javascript">
    function swapImage(intImage){
    var
    imgs=["images/pic0.jpg","images/pic1.jpg","images/pic2.jpg","images/pic3.jpg","images/pic 4.jpg",
    "images/pic5.jpg"];
    parent.frames['cont'].document.getElementById('mgmnt_pic').src =
    imgs[intImage];
    alert(parent.frames['cont'].document.getElementById('mgmnt_pic').src)
    </SCRIPT>
    then in body:
    <p><a href="javascript:; "
    onclick="frames['cont'].swapImage(0);">Management
    Team</a></p>
    i know from the alert that it is changing the source of my
    image, the problem is that the image itself is not changing at all.
    has anyone experienced this before? what can i do to fix it?

    Hi,
    chk the link
    http://javascript.internet.com/miscellaneous/random-image.html
    shanthi

  • Portal image refresh

    Hi,
    I have replaced an image in location
    /usr/sap/EPX/JC22/j2ee/cluster/server0/apps/sap.com/irj/servlet_jsp/irj/root/portalapps/com.sap.portal.design.portaldesigndata/themes/its/designs/cwwhite/webgui/wa/webgui/images/header/xx_saplogo_sim.jpg
    with a image of same name.
    Whne I try to view the image thorugh portal or directly accessing the image using url
    https://xxyy.com:52201/irj/portalapps/com.sap.portal.design.portaldesigndata/themes/its/designs/cwwhite/webgui/wa/webgui/images/header/xx_saplogo_sim.jpg
    I tried clearing navigation cache from system admin, result negative.
    I am unable to see the new image. Any idea about clearing the image cache or related cache in server side?
    thanks
    Prabhu.m...

    Hi,
    clear client cache (IExplorer) and the server cache - start Visual Admin -> Services-> HTTP Provider -> clear cache.
    Romano

  • JTextPane -captured image refreshing problem

    Dear All,
    In my application it is necessary to capture the
    screen and save it as jpeg and display the same in a JTextPane using <img> tag.
    I have made use of com.sun.image.codec.jpeg to save the image and it works fine.
    After starting the application the
    first picture is displayed well but the other pictures though get saved is not displayed in the JTextPane.Only the previous picture remains.
    I have made use of new Instance of TextPane each time.All the captured images are saved in the same name say "images/screenshot.jpg" one at a time.
    Please tell me what would be the problem.
    Expecting your reply
    Thanks and Best Regards,
    AnushaJv

    Try to remove text from the document and set it again.
    JtextPane pane;
    Document doc=pane.getDocument();
    String content=doc.getText(0,doc.getLength());
    doc.setText("");
    doc.setText(content);
    best regards
    Stas

  • JFRAME background jpeg image

    Hi,
    I am trying to add a jpeg as a packground to my JFrame. I have read quite a few posts on how to do it in here, but none seem to work . Has anybody tried this and goit it working? If so some tips would be good.
    Thanks

    With some changes, the JPanel resize to the image size:
    import javax.swing.*;
    import java.awt.*;
    import java.net.URL;
    / A <code>JFrame</code> with a background image */
    public class BackgroundImage extends JFrame
         final ImageIcon icon;
         final boolean isRedimensionable;
         public BackgroundImage(URL url, boolean isRedimensionable) {
              icon = new ImageIcon(url.getFile());
              this.isRedimensionable = isRedimensionable;
              JPanel panel = new JPanel()
                   protected void paintComponent(Graphics g)
                        if (BackgroundImage.this.isRedimensionable) {
                             //  Scale image to size of component
                             Dimension d = getSize();
                             g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
                        } else  {
                             //  Dispaly image at at full size
                             g.drawImage(icon.getImage(), 0, 0, null);
                        super.paintComponent(g);
              panel.setOpaque( false );
              getContentPane().add( panel );
              Dimension dim = new Dimension(icon.getIconWidth()  +getInsets().left+  getInsets().right, icon.getIconHeight()  +getInsets().top+  getInsets().bottom) ;
              panel.setPreferredSize(dim);
              setResizable(isRedimensionable);
              pack();
              JButton button = new JButton( "Hello" );
              panel.add( button );
         public static void main(String [] args)
              BackgroundImage frame = new BackgroundImage(BackgroundImage.class.getResource("loginDialogBackground.png"), true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

Maybe you are looking for

  • MacBook Pro dock and hard drive wont show up

    A couple days ago on my 17" 2011 MacBook Pro, the system dock and internal hard drive icon disappeared. I've restarted a few times with no luck. I unhooked all external drives and restarted but still no luck. The baffling part is that it appears to h

  • Porblem in GPIB

    Hi, every one, I try to use the following program(see attachment) to measure a resistance using scanner card of Keithley multimeter. It show the following error: " Labview.exe have generated errors and will be closed by Windows, you need to restart t

  • The phone sound not working, only the ringtone and alarm functions.

    please help with this issue.

  • How to run a pc program on a mac

    without partitioning hd.

  • Icons not showing in dock

    -just upgraded to 10.6.3 on my macbook. -icons (such as iTunes, and other random applications) do not appear in dock -printer and scanner no longer work -I suspect it may be a processor or memory issue but not sure Please advise!