Skip to content

Commit 4645230

Browse files
committed
fix for applet not adjusting canvas top for menubar
1 parent 739d7ba commit 4645230

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import javax.swing.JRootPane;
4444
import javax.swing.RepaintManager;
4545

46+
import swingjs.plaf.JSAppletUI;
47+
4648
/**
4749
* SwingJS note: This class is the original java.applet.Applet class.
4850
* It is subclassed by JApplet. The replacement java.applet.Applet class
@@ -290,6 +292,7 @@ public void resizeHTML(int width, int height) {
290292
// ((JSComponentUI)root.getUI()).setPainted(null);
291293
// root.秘isBackgroundPainted = false;
292294
RepaintManager.currentManager(this).addInvalidComponent(root);
295+
((JSAppletUI)getUI()).adjustCanvasForMenuBar();
293296
}
294297
}
295298
}

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSAppletUI.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ public DOMNode updateDOMNode() {
1818
containerNode = domNode = newDOMObject("div", id);
1919
addClass(domNode, "swingjs-window");
2020
}
21+
adjustCanvasForMenuBar();
2122
return updateDOMNodeCUI();
2223
}
2324

24-
void checkMenuBar(int h) {
25-
JMenuBar mb = ((JApplet) c).getJMenuBar();
26-
HTML5Canvas canvas = c.getAppContext().getThreadGroup().秘html5Applet._getHtml5Canvas();
27-
DOMNode.setStyles(canvas, "top", h + "px", "position", "absolute");
28-
}
29-
3025
@Override
3126
public void installUI(JComponent jc) {
3227
LookAndFeel.installColorsAndFont(jc,
@@ -51,6 +46,20 @@ public void propertyChange(PropertyChangeEvent e) {
5146
System.out.println("JSAPpletUI prop val " + prop + " " + value);
5247
}
5348

49+
/**
50+
* The JMenuBar on an applet pushes its canvas down typically about 20 pixels.
51+
*/
52+
public void adjustCanvasForMenuBar() {
53+
JMenuBar mb = ((JApplet) c).getJMenuBar();
54+
int h = (mb == null || !mb.isVisible() ? 0 : ((JSMenuBarUI) mb.getUI()).height);
55+
DOMNode.setStyles(getCanvas(), "top", h + "px", "position", "absolute");
56+
}
57+
58+
public HTML5Canvas getCanvas() {
59+
return c.getAppContext().getThreadGroup().秘html5Applet._getHtml5Canvas();
60+
}
61+
62+
5463
// @Override
5564
// public boolean isFocusable() {
5665
// return true;

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSMenuBarUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void setVisible(boolean b) {
121121
super.setVisible(b);
122122
Component top = menuBar.getTopLevelAncestor();
123123
if ( top instanceof JApplet)
124-
((JSAppletUI)((JApplet) top).getUI()).checkMenuBar(b ? height : 0);
124+
((JSAppletUI)((JApplet) top).getUI()).adjustCanvasForMenuBar();
125125
}
126126

127127
@Override

0 commit comments

Comments
 (0)