Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
695 views
in Technique[技术] by (71.8m points)

user interface - 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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...