I am working on a swing GUI and I would like to overlay a button on a progressBar. I already wrote code that updates the progress bar and button event, but I don’t know how to control the layout!
currently the panel code is as follows:
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:

I try to do this unsuccessfully:

Can someone explain to me what type of layout (or something else) I should use, or a link to my link from which I can read how to do it?
UPDATE:
adding the following code, I was able to override 2 components, but I still can’t increase the progress bar to fit the panel size:
LayoutManager overlay = new OverlayLayout(myPanel); myPanel.setLayout(overlay);
Koop4 source share