Reputation: 205
I have the following code segment in my project.
someJFrame.addComponentListener(new ComponentAdapter(){
public void componentResized(ComponentEvent e) {
pane.resize(new Dimension(getSize().width/5, getSize().height/3));
pane.revalidate();
pane.repaint();
}
});
It seems to call the componentResized() method right at the beginning when the JFrame is initialized for the first time, even though the user did not resize the JFrame- I need to prevent this from happening. I only want componetResized() to be called when a real resize has happent, and not at JFrame initialization.
Upvotes: 0
Views: 950
Reputation: 4202
Here's the way to go-
Something like this-
private boolean componentShown = false; // instance variable
someJFrame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if(componentShown) {
System.out.println("Component RESIZED");
}
}
public void componentShown(ComponentEvent e) {
componentShown = true;
}
});
Upvotes: 1