Changing size of Swing JPanel inside of an Eclipse plugin's ViewPart (despite SwingUtilities.invokeLater(Runnable()))

35 Views Asked by At

Today, I am working on an Eclipse plugin project, where I am using the standard SWT_AWT bridge in order to plug my Swing components in:

public class MyView extends ViewPart {

    public static final String ID = "HelloRCP.view";
    Frame frame;

    public void createPartControl(Composite parent) {

        Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        this.frame = SWT_AWT.new_Frame(composite);

        SwingUtilities.invokeLater(new Runnable() {

            private MainPanel swingPanel;

            public void run() {

                this.swingPanel = new MainPanel();
                frame.add(swingPanel);
            }
        });

        this.setResizeListener();

    }
    public void setFocus() {}


    private void setResizeListener() {
        this.frame.addComponentListener(new frameResizeListener(this));
    }

    public Frame getFrame() { return this.frame; } 
}

I would like to get the "frameResizeListener" to somehow trigger an update of all subsequent Swing components (e.g. JPanels) constructed by the Swing Runnable instance, this upon the ViewPart's size-change, in order to achieve some kind of responsive design. Somehow then, the underlying JPanels need to get to know about the ViewPart's Frame size...

I have read my fair share of SO Q&As, and only found the answer that "you need to pass a parameter at construction time". But my problem with this is that my usecase happes once the Components in question are already created and living...

The only solution that I see, so far, seems to break Thread-safety, by writing a shared file or property, and then signalling the Runnable to read it once done.

Can anyone else think of a better option please?

Thank you very much in advance for your support ! :) :)

Regards, Peter

0

There are 0 best solutions below