Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix for applet not adjusting canvas top for menubar
  • Loading branch information
BobHanson committed Jan 23, 2020
commit 4645230edfd55c64f39ece1862f93b7dc97d4f8c
3 changes: 3 additions & 0 deletions sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import javax.swing.JRootPane;
import javax.swing.RepaintManager;

import swingjs.plaf.JSAppletUI;

/**
* SwingJS note: This class is the original java.applet.Applet class.
* It is subclassed by JApplet. The replacement java.applet.Applet class
Expand Down Expand Up @@ -290,6 +292,7 @@ public void resizeHTML(int width, int height) {
// ((JSComponentUI)root.getUI()).setPainted(null);
// root.秘isBackgroundPainted = false;
RepaintManager.currentManager(this).addInvalidComponent(root);
((JSAppletUI)getUI()).adjustCanvasForMenuBar();
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSAppletUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ public DOMNode updateDOMNode() {
containerNode = domNode = newDOMObject("div", id);
addClass(domNode, "swingjs-window");
}
adjustCanvasForMenuBar();
return updateDOMNodeCUI();
}

void checkMenuBar(int h) {
JMenuBar mb = ((JApplet) c).getJMenuBar();
HTML5Canvas canvas = c.getAppContext().getThreadGroup().秘html5Applet._getHtml5Canvas();
DOMNode.setStyles(canvas, "top", h + "px", "position", "absolute");
}

@Override
public void installUI(JComponent jc) {
LookAndFeel.installColorsAndFont(jc,
Expand All @@ -51,6 +46,20 @@ public void propertyChange(PropertyChangeEvent e) {
System.out.println("JSAPpletUI prop val " + prop + " " + value);
}

/**
* The JMenuBar on an applet pushes its canvas down typically about 20 pixels.
*/
public void adjustCanvasForMenuBar() {
JMenuBar mb = ((JApplet) c).getJMenuBar();
int h = (mb == null || !mb.isVisible() ? 0 : ((JSMenuBarUI) mb.getUI()).height);
DOMNode.setStyles(getCanvas(), "top", h + "px", "position", "absolute");
}

public HTML5Canvas getCanvas() {
return c.getAppContext().getThreadGroup().秘html5Applet._getHtml5Canvas();
}


// @Override
// public boolean isFocusable() {
// return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void setVisible(boolean b) {
super.setVisible(b);
Component top = menuBar.getTopLevelAncestor();
if ( top instanceof JApplet)
((JSAppletUI)((JApplet) top).getUI()).checkMenuBar(b ? height : 0);
((JSAppletUI)((JApplet) top).getUI()).adjustCanvasForMenuBar();
}

@Override
Expand Down