Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run JFrame maximized in JAVA? [duplicate]

Tags:

java

swing

jframe

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();
}
like image 759
Dishon Michael Avatar asked Apr 01 '13 16:04

Dishon Michael


People also ask

How do I make a JFrame maximized?

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.

How do I make a JFrame a certain size?

You can change the size of the JFrame by simply placing the cursor in the corners and dragging it.

How do I change the default JFrame size in Java?

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.


1 Answers

You should use JFrame.setExtendedState:

public MainFrame() {
    initComponents();
    setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}
like image 62
Vishal K Avatar answered Oct 26 '22 01:10

Vishal K