There have been several questions related to this, for example here and here, that both say the way to maximize a JFrame
is to use the following code:
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //Some answers have these lines
frame.setVisible(true); //reversed
However, for me, not sure if this is a windows 10 bug/java 8 bug or not, when I use this code the result is this (no matter which way round the two lines of code above are):
As you can see in the image, the window is the correct size, however, it slightly overlays the bottom, and it is slightly offset from the left. Is there a way to fix this problem, or actually maximise the program by hitting the maximise button on the JFrame
with code?
Edit
Here is a MCVE that demonstrates the problem:
import java.awt.GridLayout;
import javax.swing.JFrame;
public class CDBurner extends JFrame {
private static final long serialVersionUID = -6027473114929970648L;
private CDBurner() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(1, 1));
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
setVisible(true);
setLocationRelativeTo(null);
requestFocus();
}
public static void main(String[] args) {
new CDBurner();
}
}