Trung
Posts: 9
Nickname: chitrung
Registered: Jun, 2002
|
|
Re: Set Minimum size of a frame
|
Posted: Jun 27, 2002 7:53 AM
|
|
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(); } } } }
|
|