问题
public class AspectRatio extends JFrame implements ComponentListener{
public AspectRatio() {
setSize(100, 100);
setVisible(true);
addComponentListener(this);
}
public static void main(String[] args){
new AspectRatio();
}
@Override
public void componentHidden(ComponentEvent e) {
// TODO Auto-generated method stub
}
@Override
public void componentMoved(ComponentEvent e) {
// TODO Auto-generated method stub
}
@Override
public void componentResized(ComponentEvent e) {
int i = Math.max(getWidth(), getHeight());
setSize(i, i);
}
@Override
public void componentShown(ComponentEvent e) {
// TODO Auto-generated method stub
}
}
Here is an example you can copy paste. Im cant speak for anyone but myself, but when i resize, the JFrame flickers wierdly. Does someone know what causing this?
Thank you in advanced.
回答1:
Sounds like an auto-refresh/auto-repaint issue. As you drag the JPane, it tries to update layout of all of its components, causing a flickering. This discussion should have the solution: How to stop the auto-repaint() when I resize the Jframe
来源:https://stackoverflow.com/questions/29353493/what-causes-the-jframe-to-flicker-while-resizing