Programmatically maximizing a JInternalFrame

Call setMaximum(true) on your JInternalFrame instance. Or call the method maximizeFrame of the DestopManager providing it with the instance of the JInternalFrame to be maximized. Here’s an example:

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.net.*;
 
public class Main extends JFrame implements ActionListener {
   JDesktopPane desktop;
   JInternalFrame frame;
 
   public Main() {
      setTitle("JInternalFrame Actions");
      desktop = new JDesktopPane(); 
      createInternalFrame(); 
      setContentPane(desktop);
      setJMenuBar(createMenuBar());
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(0);
         }
      });
 
      setSize(500, 400);
   }
 
   protected JMenuBar createMenuBar() {
      JMenuBar menuBar = new JMenuBar();
 
      JMenu menu = new JMenu("JInternalFrame Actions");
      JMenuItem menuItem = new JMenuItem("Maximize");
      menuItem.addActionListener(this);
      menu.add(menuItem);
      menuBar.add(menu);
 
      return menuBar;
   }
 
   public void actionPerformed(ActionEvent ae) {
      if (ae.getActionCommand().equals("Maximize")) {
 
         desktop.getDesktopManager().maximizeFrame(frame);
 
         /* OR:
 
         try {
            frame.setMaximum(true);
         } 
         catch(java.beans.PropertyVetoException e) {
         }
 
         */
         
      }
   }
 
   protected void createInternalFrame() {
      frame = new JInternalFrame("InternalFrame", 
         true,    // resizable
         true,    // closable
         true,    // maximizable
         true);   // iconifiable
      frame.setVisible(true); 
      desktop.add(frame);
      frame.setSize(200, 200);
      frame.setLocation(30, 30);
      try {
         frame.setSelected(true);
      } catch (java.beans.PropertyVetoException e) {}
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.setVisible(true);
   }
}