Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:13:29+00:00 2026-05-30T11:13:29+00:00

I am trying to get a JInternalFrame to be maximized when it is launched.

  • 0

I am trying to get a JInternalFrame to be maximized when it is launched. I have done web searches on this and have tried various code suggestions, but they do not seem to work properly on my machine, which is running Java 6 on Windows 7.

I have simplified the code below so that it will be easier to isolate the solution.

Can anyone show me how to change the code below so that the internal frame is maximized automatically when it is created?

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class MaximizeInternalFrame extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JLayeredPane desktop;
JInternalFrame internalFrame;

public MaximizeInternalFrame() {
    super("Test To Maximize Internal Frame");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Make the big window be indented 50 pixels from each edge of the screen.
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension screenMinus50 = new Dimension(screenSize.width - inset*2, screenSize.height - inset*2); 

    this.setPreferredSize(screenMinus50);
    desktop = new JDesktopPane();
    setJMenuBar(createMenuBar());
    this.add(desktop, BorderLayout.CENTER);
    this.pack();
    this.setSize(screenMinus50);
    this.setLocationRelativeTo(null);
}
protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    //Set up the File menu.
    JMenu FileMenu = new JMenu("File");
    FileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(FileMenu);
    //Set up the first menu item.
    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("new");
    menuItem.addActionListener(new OpenListener());
    FileMenu.add(menuItem);
    //Set up the second menu item.
    menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    FileMenu.add(menuItem);

    return menuBar;
    }
class OpenListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        // create internal frame
        internalFrame = new JInternalFrame("this internal frame needs to be maximized", true, true, true, true);
        desktop.add(internalFrame);
        internalFrame.setSize(internalFrame.getMaximumSize());
        internalFrame.pack();
        internalFrame.setVisible(true);
    }
}
public static void main(String args[]) {
    MaximizeInternalFrame myParentFrame = new MaximizeInternalFrame();
    myParentFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {if ("quit".equals(e.getActionCommand())){System.exit(0);}}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:13:30+00:00Added an answer on May 30, 2026 at 11:13 am

    Add the following after internalFrame.setVisible(true):

    try {
      internalFrame.setMaximum(true);
    } catch (PropertyVetoException e) {
      // Vetoed by internalFrame
      // ... possibly add some handling for this case
    }
    

    You can also remove internalFrame.setSize(internalFrame.getMaximumSize());

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get some licensing code from AndroidPit.com working, but I get Unable to
I am trying get the Regex right for the following scenario but have some
I've this code that uses Savon that I'm trying get to work. require savon
Trying to get this expression to work, can someone look at it and tell
Hi am trying get GPS using network provider and GPS provider. but am getting
I'm trying get only the Saturdays and Sundays between two dates, but I don't
I am trying get the html within .event_recur. $(.entry).each(function(){ alert($(this).find(.event_recur).html()); }); <div class=entry> <p
When I'm trying get method from remote webservice it gives me error. My code
I'm trying get cross compiling between 2.7.7 and 2.8.0. The package is included, this
Hello everyone I been trying get php uploader working but having a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.