🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #8632

Re: JFrame Minimum Size

#8632
From: Paul Whittington
Date: Thu, 03 Aug 2000 00:00
118 lines
3718 bytes
Frank Le wrote:
> 
> When you create your frame, overrite getMinimumSize and return new dim
>             public Dimension getMinimumSize(){
>                 return new Dimension(100, 100);
>             }

I tried overriding getMinimumSize, as you suggested, but it had no 
effect.  In fact it never gets called :(

Did I do something wrong?

Here is a small two file test program.

====================================================================
TestApplication.java
====================================================================
package Test;

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

public class TestApplication {
  boolean packFrame = false;

  //Construct the application
  public TestApplication() {
    TestFrame frame = new TestFrame();
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, 
    //  e.g. from their layout
    if (packFrame) {
      frame.pack();
    }
    else {
      frame.validate();
    }
    //Center the window
    Dimension screenSize = 
      Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
      frameSize.width = screenSize.width;
    }
    frame.setLocation
      ((screenSize.width-frameSize.width)/2, 
       (screenSize.height-frameSize.height)/2);
    frame.setVisible(true);
  }

  //Main method
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel
        (UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    new TestApplication();
  }
}


====================================================================
TestFrame.java
====================================================================
package Test;

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

public class TestFrame extends JFrame {
  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();

  //Override getMinimumSize
  public Dimension getMinimumSize(){
    return new Dimension(800, 600);
  }

  //Construct the frame
  public TestFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Test Program");
  }

  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
}

-- 
Paul Whittington
Chief Engineer
GrepNet, Inc.
paul@grep.net
Technical Details
Message-ID: <398A53A2.3D257164@grep.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <398A02E5.C216AC71@grep.net> <8md51b$299v$1@nntp1.ba.best.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,689e953802321aab
X-Google-Attributes: gid111d45,public
X-Google-Thread: 10fd6d,689e953802321aab
X-Google-Attributes: gid10fd6d,public
From: Paul Whittington <paul@grep.net>
Subject: Re: JFrame Minimum Size
Date: 2000/08/03
Message-ID: <398A53A2.3D257164@grep.net>
X-Deja-AN: 654307452
Content-Transfer-Encoding: 7bit
References: <398A02E5.C216AC71@grep.net> <8md51b$299v$1@nntp1.ba.best.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: newsabuse@supernews.com
Organization: GrepNet, Inc.
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing,comp.lang.java.gui