title: Circular Progress Bar for Java Swing not working
body: <p>i've discovered this <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html#animating">test project</a> from Oracle site because i want to add a circular progress bar in my project.</p>
  
  <p>I'm developing the application with Netbeans, and when i start the application, the JPanel where the circle should be.... disappaer.</p>
  
  <p>I've removed all the code that is not useful to solve this problem and i've got this code:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.beans.PropertyChangeEvent;
  import javax.swing.*;
  import javax.swing.plaf.LayerUI;
  
  
  public class Loading_Test extends javax.swing.JFrame
  {
      static final WaitLayerUI layerUI = new WaitLayerUI();
      public Loading_Test()
      {
  
          JPanel panel = new JPanel();
          JLayer&lt;JPanel&gt; jlayer = new JLayer&lt;&gt;(panel, layerUI);
          add(jlayer);
  
          initComponents();
      }
  
      @SuppressWarnings("unchecked")
      private void initComponents() {
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 400, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 300, Short.MAX_VALUE)
          );
  
          pack();
      }
  
      public static void main(String args[])
      {
          java.awt.EventQueue.invokeLater(new Runnable()
          {
  
              @Override
              public void run()
              {                
                  JFrame frame = new Loading_Test();
                  frame.setVisible(true);
                  layerUI.start();
              }
          });
      }
  }
  class WaitLayerUI extends LayerUI&lt;JPanel&gt; implements ActionListener
  {
  
      private boolean mIsRunning;
      private boolean mIsFadingOut;
      private Timer mTimer;
      private int mAngle;
      private int mFadeCount;
      private int mFadeLimit = 15;
  
      @Override
      public void paint(Graphics g, JComponent c)
      {
          int w = c.getWidth();
          int h = c.getHeight();
  
          // Paint the view.
          super.paint(g, c);
  
          if (!mIsRunning)
          {
              return;
          }
  
          Graphics2D g2 = (Graphics2D) g.create();
  
          float fade = (float) mFadeCount / (float) mFadeLimit;
          // Gray it out.
          Composite urComposite = g2.getComposite();
          g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade));
          g2.fillRect(0, 0, w, h);
          g2.setComposite(urComposite);
  
          // Paint the wait indicator.
          int s = Math.min(w, h) / 5;
          int cx = w / 2;
          int cy = h / 2;
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
          g2.setPaint(Color.white);
          g2.rotate(Math.PI * mAngle / 180, cx, cy);
          for (int i = 0; i &lt; 12; i++)
          {
              float scale = (11.0f - (float) i) / 11.0f;
              g2.drawLine(cx + s, cy, cx + s * 2, cy);
              g2.rotate(-Math.PI / 6, cx, cy);
              g2.setComposite(AlphaComposite.getInstance(
                      AlphaComposite.SRC_OVER, scale * fade));
          }
  
          g2.dispose();
      }
  
      @Override
      public void actionPerformed(ActionEvent e)
      {
          if (mIsRunning)
          {
              firePropertyChange("tick", 0, 1);
              mAngle += 3;
              if (mAngle &gt;= 360)
              {
                  mAngle = 0;
              }
              if (mIsFadingOut)
              {
                  if (--mFadeCount == 0)
                  {
                      mIsRunning = false;
                      mTimer.stop();
                  }
              }
              else if (mFadeCount &lt; mFadeLimit)
              {
                  mFadeCount++;
              }
          }
      }
  
      public void start()
      {
          if (mIsRunning)
          {
              return;
          }
  
          // Run a thread for animation.
          mIsRunning = true;
          mIsFadingOut = false;
          mFadeCount = 0;
          int fps = 24;
          int tick = 1000 / fps;
          mTimer = new Timer(tick, this);
          mTimer.start();
      }
  
      public void stop()
      {
          mIsFadingOut = true;
      }
  
      @Override
      public void applyPropertyChange(PropertyChangeEvent pce, JLayer l)
      {
          if ("tick".equals(pce.getPropertyName()))
          {
              l.repaint();
          }
      }
  }
  </code></pre>
  
  <p>If you run this code "as is", you should have the same my problem, the JPanel is not shown. </p>
  
  <p>But i've discovered that if i remove the layout-related lines (27~36) the progress bar starts to work.</p>
  
  <p>You also have to set manually the windows size adding</p>
  
  <pre><code>setSize(300, 300);
  </code></pre>
  
  <p>after </p>
  
  <pre><code>pack();
  </code></pre>
  
  <p>Because the layout-lines are automatically generated by Netbeans, i'm trying to understand how to solve this problem, because this particular lines of code are blocked for editing by Netbeans Editor.</p>