0

I have a JDesktopPane and a JInternalFrame. I'd like the JInternalFrame to automatically maximize after I make it. How can I hardcode the "maximize window" event?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
CodeGuy
  • 28,427
  • 76
  • 200
  • 317

3 Answers3

2

Use JInternalFrame.setMaximum(true) after you create your frame.

Here is how you can maximize your frame:

JInternalFrame frame = ...
frame..setMaximum(true); // Maximize this window to fill up the whole desktop area
GETah
  • 20,922
  • 7
  • 61
  • 103
1

Setting the method setMaximum(boolean b) of JInternalFrame to "true" , will maximize it.

eg:

JInternalFrame.setMaximum(true)
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
1

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class JInternalFrameMaximumTest {
  public JComponent makeUI() {
    final JDesktopPane desktop = new JDesktopPane();
    Action a1 = new AbstractAction("JInternalFrame#setMaximum") {
      @Override public void actionPerformed(ActionEvent e) {
        JInternalFrame f = new JInternalFrame("#",true,true,true,true);
        desktop.add(f);
        f.setVisible(true);
        try {
          f.setMaximum(true);
        } catch(java.beans.PropertyVetoException ex) {
          ex.printStackTrace();
        }
      }
    };
    Action a2 = new AbstractAction("DesktopManager#maximizeFrame(f)") {
      @Override public void actionPerformed(ActionEvent e) {
        JInternalFrame f = new JInternalFrame("#",true,true,true,true);
        desktop.add(f);
        f.setVisible(true);
        desktop.getDesktopManager().maximizeFrame(f);
      }
    };
    JToolBar toolbar = new JToolBar("toolbar");
    toolbar.add(new JButton(a1));
    toolbar.add(new JButton(a2));

    JPanel p = new JPanel(new BorderLayout());
    p.add(desktop);
    p.add(toolbar, BorderLayout.NORTH);
    return p;
  }
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override public void run() {
        createAndShowGUI();
      }
    });
  }
  public static void createAndShowGUI() {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new JInternalFrameMaximumTest().makeUI());
    f.setSize(640, 240);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
  }
}
aterai
  • 9,658
  • 4
  • 35
  • 44