Question: I'm working on a swing GUI, and i'd like to overlay a button over a progressBar.
I have already wrote the code which update the progress bar and the button event, but i don't know how to manage the Layout!

currently the panel code is the following: 

```
public static void main(String[] args) throws IOException {

        JFrame myFrame = new JFrame("myJfTitle");
        myFrame.setLayout(new BorderLayout());
        JPanel myPanel = new JPanel();
        JButton myButton = new JButton("Click me");
        JProgressBar myBar = new JProgressBar();
        myBar.setValue(50);
        myPanel.add(myButton);
        myPanel.add(myBar);
        myFrame.add(myPanel,BorderLayout.CENTER);
        myFrame.setVisible(true);
}

```

which gives the following result:

[![enter image description here](https://i.stack.imgur.com/OYCZ8.png)](https://i.stack.imgur.com/OYCZ8.png)

I'm trying unsuccesfully to obtain this: 

[![enter image description here](https://i.stack.imgur.com/rR5LG.png)](https://i.stack.imgur.com/rR5LG.png)

Can anyone explain me which kind of Layout (or whatever) should i use, or link me same reference from which i can read how to do it??

UPDATE:

by adding the following code, i managed to overly the 2 components, but i m still not able to enlarge the progress bar to fit the panel size:

```
LayoutManager overlay = new OverlayLayout(myPanel);
myPanel.setLayout(overlay);

```

Answer: 
Try with this:

```
public class Test {
    public static void main(String[] args) throws IOException {

        JFrame myFrame = new JFrame("myJfTitle");
        myFrame.setLayout(new BorderLayout());
        JButton myButton = new JButton("Click me");
        myButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        JProgressBar myBar = new JProgressBar();
        LayoutManager overlay = new OverlayLayout(myBar);
        myBar.setLayout(overlay);
        myBar.setValue(50);
        myBar.add(myButton);
        myFrame.add(myBar, BorderLayout.CENTER);
        myFrame.pack();
        myFrame.setSize(new Dimension(300,100));
        myFrame.setVisible(true);
    }
}

```
You can use GlassPane for this (Just saw your update, yours is also correct):

```
public class FTW {
    public static void main(String[] args) throws IOException {

        JFrame myFrame = new JFrame("myJfTitle");
        myFrame.setSize(300,100);
        myFrame.setLayout(new BorderLayout());
        JPanel myPanel = new JPanel();
        JButton myButton = new JButton("Click me");
        JProgressBar myBar = new JProgressBar();
        myBar.setPreferredSize(new Dimension(myFrame.getWidth(),myFrame.getHeight())); //sets the size for the first time
        myFrame.addComponentListener(new ComponentAdapter()  //sets the size everytime the frame is resized
        {  
                public void componentResized(ComponentEvent evt) {
                    Component c = (Component)evt.getSource();
                    myBar.setPreferredSize(new Dimension(myFrame.getWidth(),myFrame.getHeight()));
                }
        });
        JPanel glass = (JPanel) myFrame.getGlassPane();
        glass.setVisible(true);
        myBar.setValue(50);
        glass.add(myButton, BorderLayout.CENTER);
        myPanel.add(myBar);
        myFrame.add(myPanel);
        myFrame.revalidate();
        myFrame.repaint();
        myFrame.setVisible(true);
}
}

```