Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to make jpanel.setBackground() change my background immediately?

843807Jan 28 2010 — edited Jan 30 2010
I'm writing an app in which I need to change the background color between black and an image as soon as I issue the command. I'm new to Swing so I'm not sure what I'm missing. I can change the background just fine, but I need it to happen before anything else happens. My code looks like this:
    private void rhythmCopyingMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        try
        {
        RhythmCopyingTest rct = new RhythmCopyingTest();

        //display black screen
        mainPanel.setBackground(Color.BLACK);

        rct.doNextTrial();
        }
        catch (Exception e) {}
    }
What I wish would happen is for the background to change to black and then rct.doNextTrial() to happen. When I run this thing, rct.doNextTrial() clearly executed before the background changes to black. Does it just take a long time for the background to change?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 27 2010
Added on Jan 28 2010
3 comments
442 views