title: Layout Manager and Positioning
body: <ul>
  <li><p>how to stick JLabel in GlassPane to rellative, floating coordinates from JProgressBar without using ComponentListener or another listener, </p></li>
  <li><p>is there built_in notifiers in Standard LayoutManagers that can notify about its internal state, and can be accesible for override, instead my attempt with ComponentListener and NullLayout</p></li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/HajJ4.jpg" alt="enter image description here"></p>
  
  <p>.</p>
  
  <p><img src="https://i.stack.imgur.com/nkpC3.jpg" alt="enter image description here"></p>
  
  <p>SSCCE about <code>ComponentListener</code> and with <code>NullLayout</code></p>
  
  <pre class="lang-java prettyprint-override"><code>import java.awt.Container;
  import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.GridBagConstraints;
  import java.awt.event.ComponentAdapter;
  import java.awt.event.ComponentEvent;
  import javax.swing.JButton;
  import javax.swing.JCheckBox;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JProgressBar;
  import javax.swing.JRadioButton;
  import javax.swing.UIManager;
  //http://stackoverflow.com/questions/14560680/jprogressbar-low-values-will-not-be-displayed
  public class ProgressSample {
  
      private JFrame frame = new JFrame("GlassPane instead of JLayer");
      private JLabel label;
      private GridBagConstraints gbc = new GridBagConstraints();
      private JProgressBar progressSeven;
  
      public ProgressSample() {
          frame.setLayout(new FlowLayout());
          frame.add(new JButton("test"));
          frame.add(new JCheckBox("test"));
          frame.add(new JRadioButton("test"));
          // Nothing is displayed if value is lover that 6
          JProgressBar progressSix = new JProgressBar(0, 100);
          progressSix.setValue(2);
          frame.add(progressSix);
          // but this works value is higher that 6
          progressSeven = new JProgressBar(0, 100);
          progressSeven.addComponentListener(new ComponentAdapter() {
              @Override
              public void componentMoved(ComponentEvent e) {
                  label.setBounds(
                          (int) progressSeven.getBounds().getX(),
                          (int) progressSeven.getBounds().getY(),
                          progressSeven.getPreferredSize().width,
                          label.getPreferredSize().height);
              }
          });
          progressSeven.setValue(7);
          frame.add(progressSeven);
          label = new JLabel();
          label.setText("&lt;html&gt;Blablabla, Blablablabla&lt;br&gt;"
                  + "Blablabla, Blablablabla&lt;br&gt;"
                  + "Blablabla, Blablablabla&lt;/html&gt;");
          label.setPreferredSize(new Dimension(
                  progressSeven.getPreferredSize().width,
                  label.getPreferredSize().height));
          Container glassPane = (Container) frame.getRootPane().getGlassPane();
          glassPane.setVisible(true);
          glassPane.setLayout(null);
          glassPane.add(label, gbc);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          try {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Exception e) {
              e.printStackTrace();
          }
          ProgressSample dialogTest = new ProgressSample();
      }
  }
  </code></pre>