Resizing Frame

hi,

i am developing a chatting application..

i want to do three things in the Frame Resizing. but i don't know how to do..? any one pls help me..

1. i tried to restrict the user cann't resize the frame less than (300,600) by setSize(). it works. but the user can resize upto 0,0 .. when the user leave the mouse button for resize, then it comes to the preferedsize. i want to restrict the user cannot resize less than 300,600. How to do..?

2. when the user resize the frame size, after leave the mouse button for resize, it draws the frame based up on frame size.. i need to draw the components at the same time when i resize the frame. how to do?

3. when the frame is in resized mode, i want to show the dots (like triangle) in the right-bottom corner of the status bar to indicate the user can maximize or resize the frame. how to do..?

for example, i pasted a sample code which similar to my application.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

publicclass TestFrameextends JFrame

{

public TestFrame()

{

try

{

Toolkit toolkit = Toolkit.getDefaultToolkit();

int x = (toolkit.getScreenSize().width - getWidth()) / 2;

int y = (toolkit.getScreenSize().height - getHeight()) / 2;

Dimension dimension =new Dimension(300,600);

setTitle("TestFrame");

setPreferredSize(dimension);

setMinimumSize(dimension);

setMaximumSize(dimension);

setSize(dimension);

setLocation(x+150,y-350);

setVisible(true);

setDefaultCloseOperation(this.EXIT_ON_CLOSE);

// Event Handling

this.addComponentListener(new ComponentAdapter()

{

publicvoid componentResized(ComponentEvent e)

{

JFrame tmp = (JFrame)e.getSource();

if (tmp.getWidth()<300)

{

tmp.setSize(300, getHeight());

validate();

}

else

if(tmp.getHeight()<600)

{

tmp.setSize(getWidth(), 600);

validate();

}

elseif (tmp.getWidth()<300 && tmp.getHeight()<600)

{

tmp.setSize(300,650);

validate();

}

}

});

init();

pack();

validate();

}

catch(Exception e)

{

e.printStackTrace();

}

}

publicvoid init()

{

JButton b1 =new JButton("Button 1");

Container contentPane = this.getContentPane();

contentPane.add(b1, BorderLayout.SOUTH);

setBackground(Color.WHITE);

}

publicstaticvoid main(String[] args)

{

new TestFrame();

}

}

pls help to solve the problems..

regards,

Gokulakrishnan

[4292 byte] By [Gokulakrishnana] at [2007-10-2 6:01:58]
# 1

1) I've never seen a solution for this. But this question has been asked dozens of times, maybe I missed the solution so you can always try searching the forum (which you should have done before you posted the question anyway).

2) Toolkit.getDefaultToolkit().setDynamicLayout(true);

3) Add a "status bar" to you main frame and update the icon in a JLabel whenever the component resizes.

camickra at 2007-7-16 13:02:20 > top of Java-index,Desktop,Core GUI APIs...
# 2
hi,thank u cami..i got 2 and 3..for 1, i am trying.. for ur reference, i want to design my application's frame work like Skype's main frame.. (www.skype.com)is it possible..?let me know ur comments on this.regards,Gokulakrishnan.M
Gokulakrishnana at 2007-7-16 13:02:20 > top of Java-index,Desktop,Core GUI APIs...
# 3

Try this...

This may not be a prefect solution for u. But I think this one may help you for further.

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class sample extends JFrame implements ComponentListener

{

public sample()

{

setSize(400,400);

setDefaultCloseOperation(3);

setVisible(true);

addComponentListener(this);

}

public static void main(String ar[])

{

new sample();

}

public void componentHidden(ComponentEvent e)

{

}

public void componentMoved(ComponentEvent e)

{

}

public void componentResized(ComponentEvent e)

{

Component c = e.getComponent();

if(c.getWidth() < 300 || c.getHeight() < 300)

setSize(400,400);

}

public void componentShown(ComponentEvent e)

{

}

}

camsuresha at 2007-7-16 13:02:20 > top of Java-index,Desktop,Core GUI APIs...