1

I am working on a cool application. The frame has an alpha/transparency for the background as well as all of the panels on top of it.

When I need to change JPanels, I have it setup so one JPanel moves over to the left and the next one moves in, but in an animated way. When doing so the alpha messes up, its not as transparent anymore. If anyone could help that would be awesome but idk this one is tricky.

private class moveMainMenu implements Runnable {
    public void run(){
        try{
            int x=h.getMainMenu().getY(),y=h.getMainMenu().getY();
            for(int r=0;r<515;r++){
                h.getMainMenu().setLocation(--x,y);
                Thread.sleep(1);
            }
            h.getMainMenu().setVisible(false);
        }catch(Exception e){}
    }
}

What is set before alpha/opacity/transparent wise: (the panel being moved is a JPanel with no background, completely invisible so it must be messing up the frames background because that is what is still messed up even after the frame I am moving is gone)

    h.getFPrimary().setBackground(new Color(51,255,102,50));
JeremyF
  • 735
  • 3
  • 10
  • 19
  • 1. don't to use Thread.sleep(1); for Java6 and newer version, sleep(1) representing 1/1000 from one second, this is crazy, very short delay, latency in Native OS is 8-12milisecond, you are under this latency – mKorbel Sep 27 '13 at 19:19
  • 2. this question isn't answerable in this form, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable – mKorbel Sep 27 '13 at 19:20
  • 3. my endless curiosity where did you get h.getFPrimary() – mKorbel Sep 27 '13 at 19:21
  • @mKorbel I use a class called "Header" for all my objects, h.getFPrimary() is the actual frame. – JeremyF Sep 27 '13 at 19:47
  • @mKorbel I am confused why is using Thread.sleep(1) bad? I need the wait to be that short so the animation looks smooth and fast enough. – JeremyF Sep 27 '13 at 19:48
  • You ights like to take a look at [sliding-layout](https://github.com/AurelienRibon/sliding-layout) – MadProgrammer Sep 27 '13 at 20:24
  • 2
    Thread.sleep(1) is close enough to 0 to make no difference. Roughly speaking, 25fps is 40 milliseconds, 60fps is around 15 milliseconds. Trust me I say, 25fps is fast enough of what you want to achieve. – MadProgrammer Sep 27 '13 at 20:27
  • See also this [Q&A](http://stackoverflow.com/q/11515582/230513). – trashgod Sep 27 '13 at 20:49
  • @Jeremy Francis `I am confused why is using Thread.sleep(1) bad?` sleep is about bad practicies in Java, again for Java6 and newer version to use `Swing Timer` only, `I need the wait to be that short so the animation looks smooth and fast enough.` this isn't possible rendering with three best GPUs in SLI mode, forgot about, there isn't diplay designated for, 4-12 miliseconds is about `4k display` 3rd or 4th generations – mKorbel Sep 27 '13 at 22:09
  • @Jeremy Francis because I saw `h.getFPrimary()` a few times – mKorbel Sep 27 '13 at 22:09
  • @nKorbel I am now only using java.util.Timer and I am sure this will help be avoid many problems but this has not fixed my current issue. When I print out the location of the panel, it shows it has moved where I assigned it to but the panel is not visible even if I setVisible(true) to double check. – JeremyF Oct 01 '13 at 21:17

0 Answers0