Re: JFrame resizing
- From: Stephan Lukits <stephan.lukits@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 14:38:27 +0200
Kenneth P. Turvey schrieb:
[...][...]Ok, I can't really tell you why this isn't working, but the paint method is the wrong place for this kind of code. You should put it in a ComponentListener.
Thanks for your answer, but that dosen't work either:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Test extends JFrame {
Test() {
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if ( getSize().width != 200 || getSize().height != 100 ) {
System.out.println("Resize to 200x100");
setSize( 200, 100 );
}
}
});
}
public void paint( Graphics g ) {
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.setSize( 200, 100 );
f.setVisible( true );
}
}
regards
Stephan
.
- Follow-Ups:
- Re: JFrame resizing
- From: Kenneth P. Turvey
- Re: JFrame resizing
- From: Kenneth P. Turvey
- Re: JFrame resizing
- References:
- JFrame resizing
- From: Stephan Lukits
- Re: JFrame resizing
- From: Kenneth P. Turvey
- JFrame resizing
- Prev by Date: Re: JFrame resizing
- Next by Date: Re: JFrame resizing
- Previous by thread: Re: JFrame resizing
- Next by thread: Re: JFrame resizing
- Index(es):
Relevant Pages
|