Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>Create a JWindow (or an undecorated JFrame) with a JPanel. Leave the JWindow invisible, initially. (The wiring of this new JPanel to the same data model used by the original JPanel is left as an exercise.)</p></li> <li><p>When your maximize-panel button's ActionListener executes, it must:</p> <p>2.1. Update the (invisible) JWindow's location and size to match the (visible) JFrame's.</p> <p>2.2. Make your JFrame invisible.</p> <p>2.3. Make your JWindow visible.</p></li> <li><p>When your unmaximize-panel button's ActionListener executes, it must:</p> <p>3.1. Update the (invisible) JFrame's location and size to match the (visible) JWindow's.</p> <p>3.2. Make your JWindow invisible.</p> <p>3.3. Make your JFrame visible</p></li> </ol> <p>Example:</p> <pre><code>package stackoverflow; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class MaximizingPanelApp extends JFrame { private JPanel framePanel; private JPanel windowPanel; private JFrame maximizedFrame; public static void main(String[] args) { JFrame appFrame = new MaximizingPanelApp(); appFrame.setVisible( true ); } public MaximizingPanelApp() throws HeadlessException { super( "Application" ); setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); initialize(); } private void initialize() { // JFrame { Container container = getContentPane(); container.setLayout( new BorderLayout() ); framePanel = new JPanel(); framePanel.setBackground( Color.ORANGE ); container.add( framePanel, BorderLayout.CENTER ); JButton button = new JButton( new MaximizeAction() ); container.add( button, BorderLayout.SOUTH ); setSize( 400, 300 ); } // JWindow { maximizedFrame = new JFrame(); Container container = maximizedFrame.getContentPane(); container.setLayout( new BorderLayout() ); windowPanel = new JPanel(); windowPanel.setBackground( Color.ORANGE ); container.add( windowPanel, BorderLayout.CENTER ); JButton button = new JButton( new UnMaximizeAction() ); container.add( button, BorderLayout.SOUTH ); maximizedFrame.setSize( getSize() ); maximizedFrame.setUndecorated( true ); } } private class MaximizeAction extends AbstractAction { private MaximizeAction() { super( "Maximize" ); } public void actionPerformed(ActionEvent e) { maximizedFrame.setSize( getSize() ); maximizedFrame.setLocation( getLocation() ); setVisible( false ); maximizedFrame.setVisible( true ); } } private class UnMaximizeAction extends AbstractAction { private UnMaximizeAction() { super( "Un-Maximize" ); } public void actionPerformed(ActionEvent e) { setLocation( maximizedFrame.getLocation() ); setSize( maximizedFrame.getSize() ); maximizedFrame.setVisible( false ); maximizedFrame.dispose(); setVisible( true ); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload