JDK-4221414 : JDialog, JFrame, and JWindow shoud have setPreferredSize(Dimension)
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-03-18
  • Updated: 2001-12-05
  • Resolved: 2001-12-05
Related Reports
Duplicate :  
Description

Name: vi73552			Date: 03/17/99


JComponent can have a preferred size set
but none of JDialog, JFrame, and JWindow can.
I suppose that the three should also be able to have
preferred size set to be consistent with JComponent.

There seems to be no workarounds other than overriding
JDialog.getPreferredSize() to give JDialog a preferred size.

((JComponent)getContentPane()).setPreferredSize()
doesn't take the title bar into account.

setSize() after pack() works okay for most cases,
but I suspect it causes unnecessary recomputation of geometries.
(Review ID: 54933) 
======================================================================

Comments
WORK AROUND Name: vi73552 Date: 03/17/99 import java.awt.*; import javax.swing.*; public class JDialogWithPreferredSize extends JDialog { private Dimension preferred_size; public JDialogWithPreferredSize(Frame frame) { super(frame); } public void setPreferredSize(Dimension preferred_size) { this.preferred_size = preferred_size; } public Dimension getPreferredSize() { if (preferred_size != null) return preferred_size; return super.getPreferredSize(); } } ======================================================================
11-06-2004

EVALUATION Since JFrame, JDialog, and JWindow inherit directly from Frame, Dialog, and Window respectively (and not JComponent) they do not have setPreferredSize() and they should. We might even consider adding this to java.awt.Component. amy.fowler@Eng 2000-03-09 I'm reassigning this to awt as Amy indicates it would be good to add the setters in JComponent for min/max/pref to Component. ###@###.### 2001-10-09 A more complete summary bug is 4413805. This will be closed out as a duplicate of that more complete bug.
09-10-2001