Skip to content

Resize Listener in JFrame #21

@GoogleCodeExporter

Description

@GoogleCodeExporter
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 [email protected] on 22 Apr 2011 at 1:29

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions