JFrame resizing



Hello Group,
why doesn't the following code work?

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

class Test extends JFrame {

public void paint( Graphics g ) {
if ( getSize().width != 200 || getSize().height != 100 ) {
System.out.println("Frame Size is different");
setSize( 200, 100 );
}
g.drawString( "A test string", 50, 75);
}

public static void main( String args[] ) {
JFrame f = new Test();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout( null );
f.setVisible( true );
}
}

I'd expect it to change the frames' size after the user has
resized the frame. But that happen only occasionally.
(I actually want to make sure, that the frams' size dosen't
go below a specific size).

cat /proc/version:
Linux version 2.6.21.4-eeepc (root@LinuxPC) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #5 Thu Nov 8 17:17:35 UTC 2007

java -version:
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode)

regards
Stephan
.



Relevant Pages

  • Re: JFrame resizing
    ... class Test extends JFrame { ... public void paint(Graphics g) { ... Dimension calculateSize() { ...
    (comp.lang.java.gui)
  • Re: JFrame resizing
    ... class Test extends JFrame { ... public void paint(Graphics g) { ... JFrame f = new Test; ... java version "1.6.0_05" ...
    (comp.lang.java.gui)
  • Re: JFrame resizing
    ... class Test extends JFrame { ... public void paint(Graphics g) { ... g.drawString("A test string", 50, 75); ... Dimension calculateSize() { ...
    (comp.lang.java.gui)