Skip to content

Replace JApplet as it is removed in JDK 26 (JEP-504) #359

@bric3

Description

@bric3

JEP-504

JDK 26 means the removal of the JApplet. While this class outlived its purpose, it was one of the key component to enable Swing component inside SWT.

In particular the https://www.eclipse.org/articles/Article-Swing-SWT-Integration/index.html note explains why JApplet was specifically needed:

  • Must implement RootPaneContainer (Swing requirement)
  • Must inherit from Panel, not Window (we can't add windows to containers)
  • Must contain a heavyweight component (in order to enable AWT event handling requirement)

Only JApplet satisfied all three - JFrame/JDialog/JWindow all fail about "adding a window to a container".

Maybe it's as simple as making this simple replacement (java.awt.Panel is heavyweight, and it implements RootPaneContainer).

public class HeavyweightRootPaneContainer extends Panel implements RootPaneContainer {
    private final JRootPane rootPane = new JRootPane();

    public HeavyweightRootPaneContainer() {
        super(new BorderLayout());
        add(rootPane, BorderLayout.CENTER);
    }

    @Override
    public JRootPane getRootPane() {
        return rootPane;
    }

    @Override
    public Container getContentPane() {
        return rootPane.getContentPane();
    }

    @Override
    public void setContentPane(Container contentPane) {
        rootPane.setContentPane(contentPane);
    }

    @Override
    public JLayeredPane getLayeredPane() {
        return rootPane.getLayeredPane();
    }

    @Override
    public void setLayeredPane(JLayeredPane layeredPane) {
        rootPane.setLayeredPane(layeredPane);
    }

    @Override
    public Component getGlassPane() {
        return rootPane.getGlassPane();
    }

    @Override
    public void setGlassPane(Component glassPane) {
        rootPane.setGlassPane(glassPane);
    }
}

Also on the same issue:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions