I'm new to JAVA.
I need to run a JFrame named MainFrame
in maximized mode.
How can I do it?
public class MainFrame extends javax.swing.JFrame {
/**
* Creates new form MainFrame
*/
public MainFrame() {
initComponents();
}
By default, we can minimize a JFrame by clicking on minimize button and maximize a JFrame by clicking on maximize button at the top-right position of the screen. We can also do programmatically by using setState(JFrame. ICONIFIED) to minimize a JFrame and setState(JFrame. MAXIMIZED_BOTH) to maximize a JFrame.
You can change the size of the JFrame by simply placing the cursor in the corners and dragging it.
setPreferredSize - Sets the preferred size of this component to a constant value. Subsequent calls to getPreferredSize will always return this value. Setting the preferred size to null restores the default behavior. setMaximumSize - Sets the maximum size of this component to a constant value.
You should use JFrame.setExtendedState
:
public MainFrame() {
initComponents();
setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With