I have tried setLocation(x,y) and setLocationRelativeTo(null) by setting Layout of JFrame as null but that didn't work out.While searching I found this questions being already asked by two or three people but they have done through setLocation() and setLocationRelativeTo(null).
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.FlowLayout;
public class StartMenu{
JPanel startPanel;
JLabel title;
JButton startTest;
JButton exit;
JFrame menuFrame;
public StartMenu(){
menuFrame = new JFrame("Start Menu");
menuFrame.setLayout(null);
startPanel = new JPanel();
title = new JLabel("Adaptive Test",JLabel.CENTER);
title.setLocation(20,20);
startPanel.add(title);
startTest = new JButton("Start");
startTest.setLocation(40,40);
startPanel.add(startTest);
exit = new JButton("Exit");
exit.setLocation(100,100);
startPanel.add(exit);
menuFrame.setContentPane(startPanel);
menuFrame.setVisible(true);
menuFrame.setSize(500, 500);
menuFrame.setResizable(false);
menuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}