Image flickers when repainting

Hello,
I'm trying to make an applet where a line moves sideways as the slider is moved. The code below is working but the image flickers when repainting:
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Scrollbar;
import java.awt.event.*;
public class testSlider extends java.applet.Applet implements AdjustmentListener {
  int w, h; // Applet width and height
  Scrollbar sb;
  boolean scrollChanged = false;
  int xUnit, yUnit;
  public void init(){
    //field variables initialization
    w  = this.getSize().width ;
    h  = this.getSize().height ;
    xUnit = (int) Math.round(0.1*w);
    yUnit = (int) Math.round(0.1*h);
    sb = new Scrollbar(Scrollbar.HORIZONTAL, xUnit, 1, xUnit, 9*xUnit);
    //add Scrollbar
    sb.setBounds(5, 9*yUnit,this.getWidth() -15, 15) ;
    this.setLayout(null);
    this.add(sb);
    sb.addAdjustmentListener(this ) ;
  public void paint(Graphics g){
    System.out.println("paint...") ;
    g.setColor(Color.GRAY ) ;
    g.fillRect(0,0,w, h);
    g.setColor(Color.BLACK) ;
    //set new Origin
    g.translate(w/2, 8*yUnit) ;
    if (scrollChanged ) {
      g.setColor(Color.YELLOW  ) ;
      g.drawLine(sb.getValue()-w/2, -7*yUnit, sb.getValue()-w/2, 0  );
  //AdjustmentListener method override
  public void adjustmentValueChanged(AdjustmentEvent e){
    scrollChanged=true;
    repaint();
Can someone tell me how to prevent this flickering?
Thank you very much.

g.fillRect(0,0,w, h);This needs to modify quite a few pixels so it is going to be on the slow side.
Try this: store the coordinates of the previous line you drew. When repainting, if you have drawn a line previously, first draw the old line with the background color, then draw the new line, and finally store the coordinates of the new line so you can paint over it later.
I haven't tried that myself though.
An alternate is to use double buffering. Google: java double buffering. But that may be slowish and CPU intensive because that too needs to touch a lot of pixels.

Similar Messages

  • Hello I bought a new 11 inch 2012 macbook air. Recently, i have been watching youtube and movies from my laptop. I have seen some green images flickering when playing videos. Does anyone have any solution or the cause of the problem ? Thank you

    Hello I bought a new 11 inch 2012 macbook air. Recently, i have been watching youtube and movies from my laptop. I have seen some green images flickering when playing videos. Does anyone have any solution or the cause of the problem ? Thank you

    Hello I bought a new 11 inch 2012 macbook air. Recently, i have been watching youtube and movies from my laptop. I have seen some green images flickering when playing videos. Does anyone have any solution or the cause of the problem ? Thank you

  • How do I stop images flickering when zooming in?

    I've imported a 32bit jpeg into Director MX. I'm trying to
    slowly zoom into the image, to create a slow Ken Burns style zoom
    effect. When I play my movie, the image is flickering and the zoom
    does not appear smooth. Does anybody know a way around this? Maybe
    I'm doing something wrong...
    Any help greatly appreciated! Thanks.

    How are you performing this zoom? Are you using keyframes
    across the
    score, or using Lingo?
    If you are using the score, then you may want to try
    different frame
    rates, to see if you can smooth out the animation. You may
    also be
    seeing a problem with the refresh rate of your monitor.
    If you are using Lingo, then you might try changing the
    amount of image
    size change at each step, and/or changing the frame rate to
    smooth out
    the animation.
    Rob
    Rob Dillon
    Adobe Community Expert
    http://www.ddg-designs.com
    412-243-9119
    http://www.macromedia.com/software/trial/

  • Image flickering when animating scale

    Hi,
    Firstly i use flash 8.
    I animate a jpeg growing bigger, and its a large image over
    1600x1200. It flickers. Is there a way to prevent that?
    Best
    Andrew

    I'd say that has to do with your render settings in Motion and FCP. Without looking at them, I can't say for sure, but here's some things to be aware of.
    In MOTION:
    You can increase the quality by rendering in 16-bit, or even 32-bit.
    There are 3 render settings: Draft, Normal, Best. Default is usually set to Normal.
    Field rendering in Motion can produce poor results with progressive frame footage. Frame blending also.
    IN FCP:
    If your sequence settings are set to High Precision YUV, then that means FCP is using floating bit math for the render.
    It's possible that the Motion settings are set low, and the FCP settings are set high.
    Andy

  • DVD Slideshow Images Flickering

    I was a Window user. Now I am a new MAC user. I bought iMac mainly to do slideshows and video. I heard that MAC is great for slideshows and videos. iLife is great. But.. There is always a but. This is a big BUT and I sincerely hope that going to MAC is not a disappointment. Here goes.
    The slideshows in iPhoto 08 and iDVD 08 are great but after burning into DVD the images flickers.
    Some part of the picture flickers not the whole picture. Even the add on text on the picture flickers.
    In Windows I used Ulead Movie Factory, it had the same problem until Ulead implemented Anti Flicker option. Selecting this option makes the DVD pictures perfectly still like viewing your photos on the computer.
    Is there an Anti Flicker setting in iDVD or iPhoto?
    I am not producing DVD slideshow at the moment until I can find a solution as this flickering thingy is infuriating. A still picture must be still and not flickering on certain part of the picture/image. Railway tracks flickers madly, leaves on a tree flickers, blinds flickers, the face flickers, etc
    Please helppppppp. Frustrated. I cannot go back to Windows and I do not want to. I am sure others must have this problem too. I pray that I have done something wrong else there won't be a solution until Apple can fix it. Prayyyy
    Thanks. Sorry for being so long winded.

    Guys,
    I am back. Sorry for taking so long. My wife has been grumbling about me spending so much time on the computer, blah, blah..
    Again thank you all for all the suggestions. I have look at Photo to Movie tutorial. It is pretty good but I think Fotomagico is better. Yet to try it. Soon I hope.
    As what Howard Topoff said, Ken Burns causes the Flickering and he is correct. I created a slideshow in iPhoto without Kenburns and send to iDVD. There are no flickers what so ever. The quality I got is as per Ulead DVD Movie Factory. Now, at least I am getting the same quality as before. I expect it to be better but hey... It is really a pity as I like Ken Burns a lot.
    One thing maybe you guys can explain. iPhoto send to iDVD(not exporting) by creating a QT movie. I dragged the QT movie to Toast which has the option to tell you what type of file it is. Toast reported that the QT movie file is MPEG 4 video, 720x540 AND 13.5 fps. I would expect the fps will be around 25 or 30. Shouldn't iPhoto be sending out as high quality as possible so that iDVD will be able to recode it to suit PAL or NTSC? Unbelievable.
    It is silly for iPhoto export option which can only export the biggest is large 640x480 and iDVD will have to recode it to 720 x 576 for PAL TV.
    I have started to learn iMovie. iMovie has at least the option to set what QT quality is required when I Export Using Quicktime option. I can set whether it is PAL/NTSC/H.264,etc., frame rate, progressive or interlace, aspect ratio, etc. iPhoto has none of these. Is this an Apple oversight? I am doubtful.
    Hey, rightly or wrongly, I am beginning to be a sceptic when it comes to Apple's intentions as those things that are missing are basics that should be part of the software.
    Hopefully in a few days time, I can post more, not if my wife can help it. Nag, nag, nag.
    F Shippey, PAL is 720 x 576. I will try a few photos by resizing as per your suggestions but first I would like to look at iMovie.
    Cheers.

  • Flickering when export

    hi all
    i work with avchd 1080i50 clip,work with premiere and send to encore with dynamic link and create a bluray(i obteiy m2ts files).
    the problem is that when i see my work on full hd tv sometimes the image flickering.(the original clip don't flick if camera is connected to tv).
    i'm new of premiere pro so
    do you suggest to me to use antiflicker video effects or in video option deinterlace the entire work?
    or there are better solution?
    hi and tnx

    Check your field order.  AVCHD 1080i is upper field first.  Make sure you edit in UFF Pr sequence(s), and that you send a UFF sequence to En.
    -Jeff

  • Why does tooltip-called image flicker when it is over the trigger?

    Using a tooltip to present an image works fine when the resulting image stays away from the trigger location, e.g. offset down and to the right.  If the image is nearly full-screen, it covers the trigger location and flickers rapidly, occasionally setting after a while, but only for a moment.  Same for a small text box, if the trigger is near bottom-right on the screen, causing the tooltip content to display over the trigger site.  Any ideas to stabilize the image/text when over the trigger?

    Remove the dimensions in the following
    <div class="tooltipContent" id="sprytooltip11">  <img src="pix/1-pp-all-490x480.jpg" width="850" height="750" /></div>
    Gramps

  • My program always displays the same image, even when I change th image file

    I'm making a program that chooses an image file from a dialog, resize it and copy it into a folder. When the image is needed to be displayed, the image file is read and a JLabel displays it on screen.
    When I upload the first image, everything works fine. The problem appears when I upload another picture: the displayed image is still the first image, even when the old file doesn't exist anymore (because it has been overwritten). It looks like the image has been "cached", and no more image are loaded after the first one.
    This function takes the image picture chosen by the user, resizes it, and copy it into the pictures folder:
        private void changeProfilePicture() {
            JFileChooser jFileChooser = new JFileChooser();
            jFileChooser.setMultiSelectionEnabled(false);
            jFileChooser.setFileFilter(new ImageFileFilter());
            int result = jFileChooser.showOpenDialog(sdbFrame);
            if (JFileChooser.APPROVE_OPTION == result) {
                try {
                    //upload picture
                    File file = jFileChooser.getSelectedFile();
                    InputStream is = new BufferedInputStream(new FileInputStream(file));
                    //resize image and save
                    BufferedImage image = ImageIO.read(is);
                    BufferedImage resizedImage = resizeImage(image, 96, 96);
                    String newFileName = sdbDisplayPanel.getId() + ".png";
                    String picFolderLocation = db.getDatabaseLocation() + "/" +
                            PROFILE_PICTURE_FOLDER;
                    java.io.File dbPicFolder = new File(picFolderLocation);
                    if(!dbPicFolder.exists())  {
                        dbPicFolder.mkdir();
                    String newFilePath = picFolderLocation + "/" + newFileName;
                    File newFile = new File(newFilePath);
                    FileOutputStream fos = new FileOutputStream (newFilePath);
                    DataOutputStream dos = new DataOutputStream (fos);
                    ImageIO.write(resizedImage, "png", dos);
                    dos.close();
                    fos.close();
                    //set picture
                    sdbDisplayPanel.setImagePath(newFilePath);
                } catch (IOException ex) {
                    System.err.println("Could'nt print picture");
                }This other class actually displays the image file in a JLabel:
        public void setImagePath(String imagePath) {
            count++;
            speaker.setImagePath(imagePath);
            this.imagePath = imagePath;
            if(imagePath != null)   {
                //use uploaded picture
                try {
                    File tempFile = new File(imagePath);
                    System.out.println(tempFile.length());
                    java.net.URL imgURL = tempFile.toURI().toURL();
                    ImageIcon icon = new ImageIcon(imgURL);
                    pictureLbl.setIcon(icon);
                    // Read from a file
                } catch (IOException ex) {
                    Logger.getLogger(SDBEventClass.class.getName()).log(Level.SEVERE, null, ex);
            else    {
                //use default picture
                URL imgURL = this.getClass().getResource("/edu/usal/dia/adilo/images/noProfile.jpg");
                ImageIcon icon = new ImageIcon(imgURL, "Profile picture");
                pictureLbl.setIcon(icon);
        }

    When you flush() the image, you don't need to construct a new ImageIcon each time, a simple repaint() will suffice.
    Run this example after changing the URL to an image you can edit and update while the program is running.import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.*;
    public class FlushImage {
       Image image;
       JLabel label;
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new FlushImage().makeUI();
       public void makeUI() {
          try {
             ImageIcon icon = new ImageIcon(new URL("file:///e:/java/dot.png"));
             image = icon.getImage();
             label = new JLabel(icon);
             JButton button = new JButton("Click");
             button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                   image.flush();
                   label.repaint();
             JFrame frame = new JFrame("");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.add(label, BorderLayout.NORTH);
             frame.add(button, BorderLayout.SOUTH);
             frame.pack();
             frame.setLocationRelativeTo(null);
             frame.setVisible(true);
          } catch (MalformedURLException ex) {
             ex.printStackTrace();
    }db

  • Since installing the new update videos keep on flickering when I stream them. How can I fix this?

    Ever since I updated Firefox the videos I watch keep on flickering when I stream this. It is true of youtube, and other mediums. This is not a problem when I watch videos on Safari or Internet Explorer. I have uninstalled and reinstalled firefox to no success and restarting my computer has not helped either.

    Hello, if the Flash player is not up to date, please update it, aslo:
    Some problems with Flash video playback can be resolved by disabling hardware acceleration in your Flash Player settings. (See [[Flash Plugin - Keep it up to date and troubleshoot problems|this article]] for more information on using the Flash plugin in Firefox).
    To disable hardware acceleration in Flash Player:
    #Go to this [http://helpx.adobe.com/flash-player/kb/video-playback-issues.html#main_Solve_video_playback_issues Adobe Flash Player Help page].
    #Right-click on the Flash Player logo on that page.
    #Click on '''Settings''' in the context menu. The Adobe Flash Player Settings screen will open.
    # Click on the icon at the bottom-left of the Adobe Flash Player Settings window to open the Display panel. <br/> <br/>[[Image:fpSettings1.PNG]] <br/>
    # Remove the check mark from '''Enable hardware acceleration'''.
    # Click '''Close''' to close the Adobe Flash Player Settings Window.
    # Restart Firefox.
    This [http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html Flash Player Help - Display Settings page] has more information on Flash Player hardware acceleration, if you're interested.
    Does this solve the problem? Let us know.

  • Parts of image flickers on photos

    Parts of an image flickers on photos after burning dvd. I made a Movie using imovie 08 with 2mp photos. Used ken burns effect. Some vertical and horizontal lines may flicker, e.g. roof tops, railings, etc. Not all photos have this result. Do not notice it when viewing full screen on imovie where I made the movie. Is this the old dot crawl problem or a refresh rate issue? I used pinnacle ultimate on an old pc and did not have this issue on the final dvd product.

    That flicker is common with the Ken Burns effect. Importing your photos in with the Ken Burns effect turned on seems to help a bit, but won't totally get rid of it. Usually you notice it more on the iMovie preview playback than on the final product, which, however, does not seem to be your case. I can't recall offhand the tech explanation, but someone on this formum can tell you that.
    On the Apple website you can buy Photo to Movie, which is an app that purportedly has a smooth Ken Burns type zooming effect together with a lot of other good slide show effects. Photomaggico is another good plug-in app. Both work well with iMovie.

  • Firefox: Flickering when scrolling - need help with clean 'new' install

    Screen is flickering when scrolling (IE does not). I tried disabling add-ons and tried safe mode - neither helped. Running Win 7 Pro 64bit. Uninstalled via 'Programs and Features'. Download and reinstalled Firefox. Now it shows all my previous settings: menu bar, bookmarks bar, etc. Question: how did it get that stuff back if it 'cleanly' uninstalled? Question: how do I know it didn't pick up it's old 'bad habit' from the previous settings? I am an experienced PC user but not Firefox expert. Looking for help lest I have to ditch Firefox completely...

    Hello,
    Try disabling graphics hardware acceleration. Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches.
    You might need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
    Then perform these steps:
    #Open Firefox ''Options'' window (''Preferences'' on Mac or Linux) as follows:
    #* In Firefox 29.0 and above, click the menu button [[Image:New Fx Menu]] and select ''Options'' for Windows or ''Preferences'' on Mac or Linux.
    #* In Firefox 28.0 and previous versions, click the orange Firefox button at the top left, then select the "Options" button, or, if there is no Firefox button at the top, go to Tools > Options.
    #In the Firefox Options (or Preferences) window, click the ''Advanced'' tab, then select ''General''.
    #In the settings list, you should find the ''Use hardware acceleration when available'' checkbox. Uncheck this checkbox.
    #Now, restart Firefox and see if the problems persist.
    Additionally, please check for updates for your graphics driver by following the steps mentioned in the following Knowledge base articles:
    * [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]
    * [[Upgrade your graphics drivers to use hardware acceleration and WebGL]]
    Did this fix your problems? Please report back to us!
    Thank you.

  • Screen flickering when playing VCD

    the screen flickering throughout whenever a VCD movie is played, is this a software bug?
    (at the same time, having very poor image quality when DVD movie is played)

    have sent my Macbook to the service center, after 2 weeks, I was told that I need to downgrade to Mac OS X 10.5 (problem still exist even after updating Mac OS X 10.5.2)
    Is this confirmed a sofware problem?
    Can users of Mac OS X 10.5.2 (on MacBook) please comment.

  • Downloading images used to go automatically to the last folder used to save images, even when reopening Firefox. In just the past few days, possibly coinciding wih the most recent updates, the folder defaults to the 'Downloads' folder. This is most annoyi

    Downloading images used to go automatically to the last folder used to save images, even when reopening Firefox. In just the past few days, possibly coinciding wih the most recent updates, the folder defaults to the 'Downloads' folder. This is most annoying. What happened? Internet Explorer 8.0 did the same thing. This was one of the reasons why I started using Firefox to download all images. I went into Tools>Options and it only lets me set another folder. I dont want to set a specific folder I want it to always go to the last folder used. So what gives?
    == This happened ==
    Every time Firefox opened
    == possibly when the most recent updates were installed, a few days ago

    Thanks jscher 2000. I guess I didn't make it clear. "It restarts with all the addons activated, and resumes with the tabs that were open before closing it." IE, it's running fine now with all the extensions activated. Everything is OK now.
    So something in the Firefox code was causing the bad behavior. It's not essential that I find out what the problem was - I'm just curious. And if anybody else has this same problem, it might be nice to have it corrected at the source.

  • I am using the Adobe Acrobat Reader on a mac and I followed all the directions to copy an image but when I press paste only half of the image appears or it appears as an empty square. What can I do to fix this?

    I am using the Adobe Acrobat Reader on a mac and I followed all the directions to copy an image but when I press paste only half of the image appears or it appears as an empty square. What can I do to fix this?

    Hello,
    I would like to inform you that not all the browsers and online PDF readers support copying text from a PDF. If you have opened the PDF online, please download PDF file to your computer and then open the file in Adobe Reader.
    Please share a screenshot if the issue still persists.
    Regards,
    Nakul

  • Hey, How do I populate my replace colors color library in illustrator? I tried to replace color on a traced/ vectorized image and when I selected and went to the color library CC said I need to use a valid username. I was already logged into my adobe acco

    Hey, How do I populate my replace colors color library in illustrator? I tried to replace color on a traced/ vectorized image and when I selected and went to the color library CC said I need to use a valid username. I was already logged into my adobe account.

    Can you please show a screenshot of what exactly you want to replace where?

Maybe you are looking for

  • Multiple lables Automatic Multiply and Repeat to 12 times in a A3

    Hello there all, I've been running all over the net trying to find a solution to make my life a little easier without success so I was hoping that maybe somebody would have an idea of a better way to do this. I make personalized Tea Labels for a clie

  • My iphoto app wont load up

    when i try to start up iphoto it just keeps loading and never starts up. Apple sent me a message saying that their is a problem with iphoto . What can i do

  • Help: ORDER BY variable does not work in CS3

    I have a variable in my recordset query for the ORDER BY clause which is set by the URL variable, 'order'. With CS2 the recordset worked fine with the variable. CS3 shows N/A for the variable type in the Recordset dialog, and when I click Test to tes

  • AR Transaction/payment schedule maintance

    Hi all My client would like to update the due date on completed transactions in Oracle AR (11.5.8). As known, this can be done manually in the 'Transaction Summary -> Installments' screen in AR, but my client would like this task to be automated. My

  • Can anyone Reproduce This screencast? Strange behavior from Mac

    https://drive.google.com/file/d/0B5LXJD4aR7maZng4cnl6Z2UxS28/edit?usp=sharing 1.  Open finder and click go 2.  go to /var 3.  click on var alias and go to at file After you open the /var/at folder there is a file called at.deny 4.  Click on the file