One way is to use the Extended State. This asks the underlying OS to maximize the JFrame.
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
Other approach would be to manually maximize the screen for you requirement.
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(100, 100, (int) dim.getWidth(), (int) dim.getHeight());
setLocationRelativeTo(null);
But this has pitfalls in Ubuntu OS. The work around I found was this.
if (SystemHelper.isUnix()) {
getContentPane().setPreferredSize(
Toolkit.getDefaultToolkit().getScreenSize());
pack();
setResizable(false);
show();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Point p = new Point(0, 0);
SwingUtilities.convertPointToScreen(p, getContentPane());
Point l = getLocation();
l.x -= p.x;
l.y -= p.y;
setLocation(p);
}
});
}
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(100, 100, (int) dim.getWidth(), (int) dim.getHeight());
setLocationRelativeTo(null);
In Fedora the above problem is not present. But there are complications involved with Gnome or KDE. So better be careful. Hope this helps.