Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Have JFrame respect the minimum size (stop resizing) - Partial solution

843805Aug 21 2006 — edited Aug 21 2006
Hi

I remember I searched for a solution to make JFrame respect the minimum size of itself or it's components, but unfortunately there is no solution, at least not a satisfactory one.
The force-a-resize-if-it-gets-too-small "solution" looks really bad so I desided to drop the whole thing.

However I've been testing around with different Look & Feels and changing the layout, and what I discovered is that when setting setDefaultLookAndFeelDecorated(true) the minimum size is respected.

I haven't seen anyone mentioning this I thought I'd post it here.
import javax.swing.*;
import java.awt.*;

class RespectMinimumSize extends JFrame {
    
    RespectMinimumSize() {
	setMinimumSize(new Dimension(400, 400));
	setLocationRelativeTo(null);
	
	pack();
	setVisible(true);
    }
    
    public static void main(String [] args) {
	
	JFrame.setDefaultLookAndFeelDecorated(true);
	JDialog.setDefaultLookAndFeelDecorated(true); // Works with JDialog as well
	Toolkit.getDefaultToolkit().setDynamicLayout(true);
	
	new RespectMinimumSize();
    }
}

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 18 2006
Added on Aug 21 2006
1 comment
937 views