Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting minimum size limit for a window in java swing

I have a JFrame which has 3 JPanels in GridBagLayout..

Now, when I minimize a windows, after a certain limit, the third JPanel tends to disappear. I tried setting minimizing size of JFrame using setMinimumSize(new Dimension(int,int)) but no success. The windows can still be minimized.

So, I actually want to make a threshhold, that my window cannot be minimized after a certain limit.

How can I do so?

Code:-

import java.awt.Dimension;  import javax.swing.JFrame;  public class JFrameExample {     public static void main(String[] args) {         JFrame frame = new JFrame("Hello World");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         frame.setMinimumSize(new Dimension(400, 400));         frame.setVisible(true);     } } 

Also:

shadyabhi@shadyabhi-desktop:~/java$ java --showversion java version "1.5.0" gij (GNU libgcj) version 4.4.1  Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Usage: gij [OPTION] ... CLASS [ARGS] ...           to invoke CLASS.main, or        gij -jar [OPTION] ... JARFILE [ARGS] ...           to execute a jar file Try `gij --help' for more information. shadyabhi@shadyabhi-desktop:~/java$ 

Gives me output like

alt text

**UPDATE: ** The same when run though Netbeans IDE gives expected output.. When I run through "java JFrameExample" compiler, I am facing issues.. Now, what that means??

like image 384
Abhijeet Rastogi Avatar asked May 06 '10 14:05

Abhijeet Rastogi


People also ask

How do I change the size of my Java Swing in Windows?

Using setSize() you can give the size of frame you want but if you use pack() , it will automatically change the size of the frames according to the size of components in it.

What is content pane in Java Swing?

In Java Swing, the layer that is used to hold objects is called the content pane. Objects are added to the content pane layer of the container. The getContentPane() method retrieves the content pane layer so that you can add an object to it. The content pane is an object created by the Java run time environment.


1 Answers

The documentation tells me, that this behavior is platform dependent. Especially, since the following example code works for me as desired in Windows Vista:

import java.awt.Dimension;  import javax.swing.JFrame;  public class JFrameExample {     public static void main(String[] args) {         JFrame frame = new JFrame("Hello World");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         frame.setMinimumSize(new Dimension(100, 100));         frame.setVisible(true);     } } 
like image 73
ablaeul Avatar answered Oct 12 '22 18:10

ablaeul