I want to place a button on the JFrame title bar as in the below image.
When I set the bounds for the button using button.setBounds(), the button hides under the title bar as below.
I have given below the code that I had tried.
public class SetBoundsTest {
       public static void main(String arg[]) {
          JFrame frame = new JFrame("Test Frame");
          frame.setSize(500, 250);
          // Setting layout as null
          frame.setLayout(null);
          
          // Creating Button
          JButton button = new JButton("Test");
          // Setting position and size of a button
          button.setBounds(150,-20,120,40);
          button.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));
          button.setBackground(Color.MAGENTA);
          frame.add(button);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    }
Any help is greatly appreciated.


                        
You can set your frame to undecorated like this
Note: Add this statement before
frame.setVisiblle(true);