Re: JFrame resizing



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
.



Relevant Pages

  • Re: issue with printing using jdic
    ... The default implementation of this method calls the paint method. ... The origin of the graphics context, its coordinate point, is ... WebBrowser webBrowser=new WebBrowser; ... public void mouseClicked{ ...
    (comp.lang.java.gui)
  • Re: Actionlisstener
    ... > i need to create an applet a GUI IfBut.java which contains three ... > public void actionPerformed ... Then in your paint method use that variable when setting the colour: ...
    (comp.lang.java.help)
  • getText() question
    ... input from the textbox and display it with the paint method when the user ... public void actionPerformed ...
    (comp.lang.java.help)
  • imagebuffered problem
    ... this is my paint method i am trying to print on screen something with the bufferedImage but i cant see anything.thanx in advance. ... public void paint ...
    (comp.lang.java.programmer)