Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize Listener in JFrame #21

Open
GoogleCodeExporter opened this issue Jul 27, 2015 · 0 comments
Open

Resize Listener in JFrame #21

GoogleCodeExporter opened this issue Jul 27, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

The resize listener for JFrame is not working properly, because it is called at 
the end of an resize event (and not continously while resizing).

Solution:
The ComponentListener (ComponentAdapter) has to be added to the ContentPane of 
the JFrame. This Listener will only receive resize events, because the 
ContentPane will never be moved relative to the JFrame.

Suggestion:

// in SwingComponent
final Component resizeListenerComponent;  // may be replaced by method
if (getUiReference() instanceof JFrame) {
    resizeListenerComponent = ((JFrame) getUiReference()).getContentPane();
}
else {
    resizeListenerComponent = getUiReference();
}
resizeListenerComponent.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(final ComponentEvent e) {
        componentObservable.fireSizeChanged();
    }
});

getUiReference().addComponentListener(new ComponentAdapter() {

    @Override
    public void componentMoved(final ComponentEvent e) {
        componentObservable.firePositionChanged();
    }
});

Original issue reported on code.google.com by googlec...@dev.nikolaus-moll.de on 22 Apr 2011 at 1:29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant