When to repaint panel?

I'm having a problem figuring out when exactly my panel is ready to be repainted. Inside this JPanel I'm loading Images and then drawing them with paintComponent. My problem is that when the panel is first painted, these images aren't loaded yet so paintComponent can't draw them. However, after a second or so these images are loaded and if I force a repaint by resizing the window everything shows up fine.
What's the best way to repaint the panel when the Images are loaded? I tried a thread approach but I was running into problems where for some reason the images would never load (as if the thread was taking over the whole program) and I would like to avoid threads if possible. Any suggestions would be greatly appreciated.

Synchronous loading means that your application stops everything until the image is fully-loaded, then continues on its way. Asynchronous loading means the app moves ahead without loading the image; not a desirable thing. The old boiler plate method for synchronous loading is with a MediaTracker. The newer way is with ImageIO but this requires j2se 1.4 or later. If you will load or initiate the loading of your images in the constructor of your app/component they will be ready when the app/component is first painted.
class AnImageComponent extends JPanel
    BufferedImage/Image image;
    public AnImageComponent()
        loadImage();
    protected void paintComponent(Graphics g)
        g.drawImage(image, x, y, this);
    private void loadImage()
        // synchronously load image...
}The override of the 'update' method is not recommended and usually not necessary in Swing. Calling 'repaint' and/or 'validate/revalidate' for updating gui components is usually done from within event code, eg, from within the actionPerformed method of a SwingTimer, a while loop inside an animation thread, or a ui component event listener.

Similar Messages

  • PowerMac G5 will ONLY boot up when the side panel is removed

    Hi,
    We have a PowerMac G5 Dual 2.5GHZ . This mac will ONLY boot up when the side panel and the clear plastic panel are removed. If the Mac is assembled, the Mac will start and Chime, but thats it. No display and the fans are dead quite. Any Suggestions? Thanks in advance

    Hi, I realised that this problem has ONLY occured AFTER I installed Leopard. I then reformated the hard drive and installed 10.34 ( the OS that came with the G5) and it is as good as gold. I then reformated the hard drive and installed Leopard. After a few minutes the G5 became noisy and unstable. I then reformatted the hard drive AGAIN and reinstalled 10.34 and it stable. How can I install Leopard without the machine behaving erratic? Thanks for any advice in advance

  • Why am I getting the flag Invalid URL for web content overlay when making scrolling panel in Indesig

    Why am I getting the flag 'Invalid URL for web content overlay" when making scrolling panel in Indesign? Iam making additions to existing articles but the problem is new. The articles were originally made using CS and now I am on CC, which I have just uninstalled and re installed, no difference, can anyone help please? Steve

    Hi Bob, thankyou very much for coming back on this. The flag is coming up towards the end of the preview process on desk top. I have made dozens if not hundreds on my two published apps on the app store, but have not done an update for nearly a year, in which time I have needed a refresher, and as usual went to Lynda. In this case I have followed to the letter your DPS course, which is great, and I found the process of making the scrolling panels somewhat easier than when I started 2-3years ago. Initially I was mystified that the flag talked about url and web content, but just put it down to something I had missed in recent improvements in CC.
    I tried over and over, but always got the same result. I thought at one point it might be because the content of my slide was copy and photo, so for a test I deleted the photo. Same result, and many of my existing slides are copy and picture.
    I also uninstalled Indesign CC and reinstalled in case of corrupted content, I also copied to IDML and relaunch, same problem. I am sure I have made the scrolling content as instructed, The one thing I havn't done is trash my preferences, if you think that would be a good Idea could you please direct me to some content at Lynda on how to do it in CC. Many thanks, Steve

  • Not repaint panel when scene moved

    hi, i have next components. JPanel, which contains JScrollPane with JLabel on it. Right now, when mouse moves over JPanel, all of those components (or at least JLabel) are repainted.
    How i can forbid repaint method on mouse moved event?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Repaint extends MouseMotionAdapter
        JLabel report = new JLabel(" ", JLabel.CENTER);
        public static void main(String[] args)
            Repaint test = new Repaint();
            TalkingLabel label = new TalkingLabel("label");
            label.addMouseMotionListener(test);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(label));
            f.getContentPane().add(test.report, "South");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        public void mouseMoved(MouseEvent e)
            // did you do something here to cause repainting?
            report.setText("x = " + e.getX() + "  y = " + e.getY());
    class TalkingLabel extends JLabel
        public TalkingLabel(String text)
            super(text, CENTER);
            setFont(getFont().deriveFont(18f));
            setBackground(Color.pink);
        protected void paintComponent(Graphics g)
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                             RenderingHints.VALUE_ANTIALIAS_ON);
            super.paintComponent(g);
            System.out.println("talking label is repainting itself");
    }

  • Repainting Panel from within ActionEvent

    Hey everybody,
    let me draw a little picture of my problem.
    I have a JFrame, with two panels A and B. There 's also a JButton on panel A. When I press that button, I want a new JButton shown in panel B.
    Here's my code for the ActionListener:
    class ButtonPressed implements ActionListener {
              public void actionPerformed(ActionEvent e){
                   SwingUtilities.invokeLater(new Runnable() {
                               public void run() {
                                         panelA.add(new JButton("test"));
                                                                          panelA.repaint();
                         System.out.println("Test pressed in runnable");
         }Now, my problem is that no button appears... Although the actionPerformed method is really invoked, because the system.out.println()-line prints on the screen.
    I browsed the forum, and most of the same problems are thread-related. But as you can see, I do use the SwingUtilities.invokeLater() method.
    I've also tried to comment out the panelA.repaint() line, but that didn't work.
    Can anybody help?
    Thanx,
    Piotr

    You are misunderstanding when to use SwingUtilities.invokeLater(...). This method is used to add code to the Event Thread for execution and is only required when you program is using threads. Any code that is executed in any Event Listener is already executing in the Event Thread, so you don't need to use the invokeLater.
    When you add or remove a component from a container you need to revalidate the container so the components can be layed out correctly. So your code should be:
    panel.add(...);
    panel.revalidate();
    // if the above doesn't work, then also add the following
    //panel.repaint();

  • Reference to control on main front panel fails when subvi front panel is closed?

    Hi All,
    I'm experiencing an odd bug. In my code, I use a subvi to control a piece of hardware. This subvi has controls for all of the functions of my hardware.
    I'm changing the value of one of these controls from my main front panel by running a reference to a knob on my main front panel into the subvi, grabbing the value of the knob with a property node, and then updating the value of the subvi control using a signaling property node.
    This works fine when my subvi front panel is open but fails to work at all when the subvi front panel is closed.
    I'm new to labview , so any help is appreciated.
    Thanks,
    Arpan
    Solved!
    Go to Solution.

    What is your LabVIEW version?
    Front panels that are not shown are typically not updated and might not even be loaded into memory.
    The presence of certain code elements (e.g. property nodes) often forces the front panel to be in memory even if it is not shown, but I haven't studied it in a long time so there might be subtleties. Maybe somebody from NI can give more details.
    If it does not work unles the FP is open, open the front panel minimized to avoid distraction.
    Can you attach some code? Maybe there are better ways to do all this anyway.
    LabVIEW Champion . Do more with less code and in less time .

  • InDesign Crashes when Accessing Character Panel

    I just updated my Mac OS 10.6.7 with CS5 after uninstalling CS3, which functioned without any problems.  Now, after both creating new documents and opening previously created documents, InDesign is having all kinds of problems when I attempt to access the font list in the character panel.
    InDesign will crash everytime while I am scrolling through the font list.  I have tried using the Characer Panel window, as well as the font option at the top when using the text tool.  InDesign crashes either way.
    I have validated all of my fonts, removing those who were tagged as corrupt, uninstalled & reinstalled inDesign, and also removed my perferences folders to restore to default workspaces.  After all of that, InDesign continues to crash.
    Does anyone have any suggestions on what to do next?  I thought at first it was a corrupt font file, but now I'm not sure what it could be.

    There are some probems that do affect InDesign though.
    The one I've seen is fleeting.
    Open a document and set a substantial quantity of text (say, a full page) in Utopia Std 12pt. (We're using Version 2.050; PS 2.000; hotconv 1.0.51;makeotf.lib2.0.18671). Open LibreOffice 3.3.1. Quit Libreoffice.
    InDesign activates (it was the last app open) and pops up the Missing Fonts dialog, saying that Utopia Std is no longer on the system, and every character changes to a missing-font rectangle.
    A few seconds later all the rectangles go away. But this is not proper behavior...

  • InDesign crashes when opening certain panels

    InDesign has been acting up since yesterday with a product catalog that I have been developing.
    Anytime that I have the file open and I try to access the cross reference panel or the hyperlinks panel, ID crashes.
    If I open the panels without the file. It works fine. But only when I open the file back up do I have issues.
    Also, ID has been running VERY slow when this file is open.
    Any help is appreciated.
    Thanks!
    Mac OS X 10.9
    InDesign CC v9.2

    I should note that it works fine on other computers now too. Just not my desktop.

  • How to display field when using Query Panel..

    Hello,
    I created a Named Criteria with a bindvariables then I drag the Named Criteria I created to the page with ADF Query Panel, then I drag the VO where the Named Criteria to the page with ADF Form.
    now what I need ..
    I need the Fields in ADF Form (input text....) to be displayed befor I cliked the search button. becasue the page design will appear bad. so how can I dislpay them when the page load.
    Thanks,

    May be you need to update the values of the screen field like:
    DATA BEGIN OF LNA_DYNPF OCCURS 1.
    INCLUDE STRUCTURE DYNPREAD.
    DATA END OF LNA_DYNPF.
        l_total = l_total + S10_QUANTITY.
        LNA_DYNPF-FIELDNAME  = 'S10_TOTAL_PRICE'.   " field name
        LNA_DYNPF-FIELDVALUE = l_total.   " value
        APPEND LNA_DYNPF.
        CALL FUNCTION 'DYNP_VALUES_UPDATE'
             EXPORTING
                  DYNAME               = l_cporg        " your program
                  DYNUMB               = '0100'  " your screen
             TABLES
                  DYNPFIELDS           = LNA_DYNPF
             EXCEPTIONS
                  INVALID_ABAPWORKAREA = 1
                  INVALID_DYNPROFIELD  = 2
                  INVALID_DYNPRONAME   = 3
                  INVALID_DYNPRONUMMER = 4
                  INVALID_REQUEST      = 5
                  NO_FIELDDESCRIPTION  = 6
                  UNDEFIND_ERROR       = 7
                  OTHERS               = 8.
    Regards,
    Naimesh Patel

  • Bug in Flash 8 when using Strings Panel?

    A problem with the strings panel in Flash 8 I have found is
    that, when working with 6 languages, if you save and close down
    your Flash file with the Strings panel hidden, and re-open the FLA
    and then view the strings panel/view your text on the stage (or
    open the xml file) that, in my cae, some EN strings have been
    corrupted/mutated to other languages.
    This is obviously a bug in Flash which corrupts one of the
    XML files if the strings panel is closed. Why does it do this? Its
    very annoying having to remember to open the strings panel whenever
    I load that specific project, even if I am not going to use it. And
    the panel takes up a lot of space as it is so can't leave it open
    all the time for other projects.
    Any ideas?

    Howdy. I'm having a very similar problem. I'm working with 21
    languages (including EN) on the strings panel in Flash 8. I've
    found that my languages get corrupted -- EN strings get substituted
    in for some, not all localized strings in the panel -- when I
    publish or test the movie. I was publishing for Flash 7. When I
    changed my publishing settings to Flash 8, the problem went away.
    Have you gotten any answers to your problem?

  • Error message when using snippets panel

    Everytime I click on the snippets panel, I get the following message:
    The following JavaScript error(s) occurred:
    SyntaxError: missing ) after argument list
    I tried making a new user on my computer but get the same error message with that user as well.
    I am using Mac OS 10.6.3. Master Collection CS5.
    Any help would be appreciated.
    Thanks.

    WOW! it's solved. i had the same problem.
    there's sth i'd like to share. i guess when some devices try to see my name, (some windows systems), like when i create a wireless network so they can connect to me and i can share files with them on my mac, the name they see on their screen is very weird. the opostroph is a bunch of other characters. i don't know to call this a mac bug or an adobe bug! maybe both. since i don't know what it has to do with the name of the hard disk, how did u know this anyway? i mean there's NO WAY i could have possibly thought it's because of this.
    PS: THANX SO SO SO MUCH again. there's NO WHERE on the web, that talked about this. this is the 1st place!

  • AE 2014.2 crash when switching preview panel with Matrox

    I newly bought a pc with Matrox M9138 card, and using it for professional use. All works fine, except for Adobe After Effects CC 2014.2: it simply crashes when switching between the Preview-panel and Render-Cue panel.
    When I look in AE preferences under Video-preview > Mercury transmit doesn't even show that there is a Matrox-card. The only option there is Adobe DV. So, I guess AE doesn't find and even makes use of my Matrox card.
    Technical info:
    Windows Version: 8.1
    Processor: Intel Core i7-4790 CPU, 3.6 GHz
    RAM: 16GB
    Type: 64bits
    Matrox M9138 LP PCIex16
    Driver version 2.4.3.2 (4.4.3.2) for Win 8-64bit
    Adobe CC After effects 2014.2
    After Efects error: "Crash in progress. Last logged message was: <816><ae.blitpipe><2> Making New Context"
    First I installed the Matrox driver, and then Adobe CC, but After effects crashed when switching between preview-panel and render-cue-panel (No Matrox recognition in AE preferences > Mercury transmit)
    Now I did it in other order:
    - I removed Adobe CC (AE included) and all parts
    - Did extra checkup removal with Adobe CC cleaner
    - Removed the Matrox driver
    - Restarted PC
    - Reinstalled Adobe CC with AE
    - Reinstalled Matrox Driver
    - Restarted PC
    - matrox fully installed and working perfectly (no errors in Display Adapters info).
    But still, After effects crashed (Still no Matrox recognition in AE preferences > Mercury transmit)
    I contacted Matrox technical support, and as I suspected, they say they haven't had this problem before and all works fine.
    Typical...
    Does someone has an idea what the problem would be?
    Help or info would be very appreciated.

    Solution:
    My graphics card did not supported the "Mercury Playback Engine GPU Acceleration (Open CL)". You can change it into "Mercury Playback Engine Software Only" in your Project Settings.
    But this is in the wrong place in my opinion. Why not in "Edit/Preferences"? I could've changed it by myself but I did not find the menu.
    Thanks Michaela from the Adobe Support Chat!

  • Stops working when  "Starting up panels..."

    Just bought Adobe Creative Suite 5.5 Design Standard.  InDesign refuses to load.  I get the error message:
    Adobe InDesign CS5.5 has stopped working.
    A problem caused the program to stop working correctly.
    Windows will close the program and notify you if a solution is available.
    Illustrator and Photoshop load and seem to work okay.  (Did not go beyond loading program.)
    I uninstalled and reinstalled the suite but still can only load Illustrator and Photoshop.
    InDesign stops loading when it gets to "Starting up panels..."
    I did change the resolution so my monitor displayed correctly.
    Any suggestions?

    I'm having pretty much the same problem.  When I try to launch InDesign CS5.5 I receive the error message from Windows:  Adobe InDesign CS5.5 has stopped working.
    I have the Creative Suite 5.5 Design Premium Student and Teacher Edition, running on Windows 7 Home Edition Premium 64 bit
    I have tried opening InDesign directly and get the error message, and I've tried opening from a document and get the same message.
    Recently I had to move to a new computer, as my old hard-drive boot died on the old one, so I was not able to uninstall Creative Suite 5.5 from the old computer.  However, the rest of the Suite works fine, just not InDesign.
    I have tried the fix as per Peter Spiers' post above; I renamed the InDesign SavedData file, but there was no InDesign Defaults file.  I searched for adobefnt*.lst files, but there were none.
    I've not successfully used InDesign since loading it on this new computer, so perhaps this makes a difference?

  • AE CC Freezes when using Layers panel

    Hello all,
         I'm having an issue with the Layers panel, which is docked to my Comp panel, freezing my system whenever I try to click into any other panel. I can open a project, click on a layer to do some painting and then if I try to go back to the Comp panel...it freezes. My only solution is to open the Task Manager and shut down AE. If I save everything before I try to get out of the Layers panel then I am okay but that getting old fast.
         I'm working on an hp Z420 Workstation. This system is entirely new as of December 2013 and there haven't been any major  issues but this has popped up and it's getting in the way of production.
    Thanks,
    Fred

    Running Windows 7 and AE6 is version 12.2.0.52 and I'm on the Cloud so it stays up to date.
    We have two identical suites and we just tested the other one with the same results. The Layer window freezes AE whenever I dock it with the Comp window.  I can dock Layers with any other window and I can dock any other window with the Comp window and they work fine...but for some reason the Layer and Comp windows don't play nice together.
    I have tested it in old projects, new projects, with footage, without footage, in my personal workspace, in the AE workspace options. I keep my system pretty clean when it comes to memory so that isn't an issue. Plus, the other system rarely ever runs AE so that nulifies the memory option.
    Thanks,
    Fred

  • Why crashes LV 8.0.1 when opening remote panel

    Hi everybody,
    everytime I try to open a remote panel to my vi from another VI Labview (remote client) crashes completely. It worked fine with LV 8.0 but not with LV 8.0.1 on a linux machine (Suse 10.0). When I try to open the panel in a browser it says that the run time engine is missing. But installing the rte doesn't work because the script says it's already installed. There is no difference if I try it locally or on a remote machine, both running LV 8.0.1 on Suse linux 10.0.
    I'd appreciate any tip, thanks
    Clemens

    Hi Robert,
    I just gave up using Lv 8.0.1 because I had nothing but problems with it and the original problem I instellad it for wasn't solved and in the meantime I was told I had to live with it. The strange thing with the RTE was that it worked with some vi's but not with all. But it worked with all vi's usting LV 80. The migration form LV 7.1 to 8.xx took so much time that I'll stay as long as possible with it ignoring all further updates.
    Regards Clemens

Maybe you are looking for

  • Does PI 7.1 EHP1 supports java version 1.6?

    Does PI 7.1 EHP1 supports java 1.6? Where do i find these details?

  • Kdemod 4.2 with dual head

    I want to use dual head setting in kde 4.2 but it has bunch of issues. When in kde4 i issue the command xrandr --output VGA --left-of LVDS , it enable the dual head setup but the resolution defaults to 1024x768 for both my monitor and Laptop. When I

  • Mid 2013 MBA 11in Intel HD 5000 with 10.9.3 update problems

    Hello all, After updating my mid 2013 macbook air with a Intel HD 5000 to 10.9.3 i have noticed significant screen lag when in an occassion of toggling through windows, scrolling up/down through pages, swipping through full-screen apps, and such. It

  • Another annoying artwork issue

    After reading this forum for quite a while, I noticed that most artwork issues concern wrong pictures or black screen. Well, I have a slightly different problem: Some tracks (albums) display the correct artwork when the device is held in "portrait" p

  • NI Developer Suite 8.2 / LV Runtime Engine 8.2 vs 7.1.1

    I have NI Developer Suite 8.2 and have installed LabVIEW v8.2 from it onto my development computer.  I have converted a LabVIEW 6.1 application to 8.2 and am now setting up an installer build for the application. When setting up installer build prope