The Artima Developer Community
Sponsored Link

Java Answers Forum
Set Minimum size of a frame

1 reply on 1 page. Most recent reply: Jun 27, 2002 7:53 AM by Trung

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
james smith

Posts: 8
Nickname: jochem
Registered: Apr, 2002

Set Minimum size of a frame Posted: Jun 27, 2002 2:13 AM
Reply to this message Reply
Advertisement
Does anyone know how to set the minimum size of a frame sothat when I click on the bottom of my application, the window can shrink to a certain size and then stop?


Trung

Posts: 9
Nickname: chitrung
Registered: Jun, 2002

Re: Set Minimum size of a frame Posted: Jun 27, 2002 7:53 AM
Reply to this message Reply
Hi,
I am not sure if i understood what you mean.
well, with the method setSize() you can set the size of your frame.
and if you dont want the user to shrink the frame too small at all...
well, i just found out how i could do it with the TimerTask. anyway may be it is usefull for you...
if you know another way, please let me know!
here is the code :

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

public class test {
JFrame frame = new JFrame("Test");
Container c = frame.getContentPane();
JPanel panel = new JPanel();
JTextArea textarea = new JTextArea(5,20);
JScrollPane scrollpane = new JScrollPane(textarea);
java.util.Timer timer = new java.util.Timer();

public void openFrame() {
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

timer.schedule(new setMinimumSize(), 0, 1);

c.add(panel, BorderLayout.CENTER);
panel.add(scrollpane);
frame.pack();
frame.show();
}

public static void main(String args[]) {
test newtest = new test();
newtest.openFrame();
}

class setMinimumSize extends TimerTask {
public void run() {
if (frame.getSize().getWidth() < 200||
frame.getHeight() < 200){
frame.pack();
}
}
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Splash screen which JAVA ??? Previous Topic   Next Topic Topic: JAAS

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use