Skip to content

Commit 484ae93

Browse files
hansonrhansonr
authored andcommitted
Top-Level AWT components return a default font even after setFont(null)
1 parent 54c53f9 commit 484ae93

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

sources/net.sf.j2s.java.core/src/swingjs/a2s/Applet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.awt.Color;
44
import java.awt.FlowLayout;
5+
import java.awt.Font;
56
import java.awt.HeadlessException;
67
import java.net.MalformedURLException;
78
import java.net.URL;
@@ -30,6 +31,13 @@ public Applet() throws HeadlessException {
3031
((JComponent) getContentPane()).setOpaque(false);
3132
}
3233

34+
@Override
35+
public Font getFont() {
36+
if (font == null && parent == null)
37+
font = new Font(Font.DIALOG, Font.PLAIN, 12);
38+
return super.getFont();
39+
}
40+
3341
@Override
3442
public void setBackground(Color c) {
3543
super.setBackground(c);

sources/net.sf.j2s.java.core/src/swingjs/a2s/Dialog.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package swingjs.a2s;
22

3+
import java.awt.Font;
34
import java.awt.GraphicsConfiguration;
45
import java.awt.Window;
56

@@ -19,9 +20,15 @@ private void setListener() {
1920
Util.setAWTWindowDefaults(this);
2021
}
2122

23+
@Override
24+
public Font getFont() {
25+
if (font == null && parent == null)
26+
font = new Font(Font.DIALOG, Font.PLAIN, 12);
27+
return super.getFont();
28+
}
29+
2230
public Dialog(Frame owner) {
23-
super(owner);
24-
setListener();
31+
this(owner, false);
2532
}
2633

2734
public Dialog(java.awt.Frame owner, boolean modal) {

sources/net.sf.j2s.java.core/src/swingjs/a2s/Frame.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package swingjs.a2s;
22

33
import java.awt.Component;
4+
import java.awt.Font;
45
import java.awt.GraphicsConfiguration;
56
import java.awt.MenuBar;
67
import java.awt.MenuComponent;
@@ -48,10 +49,14 @@ public void windowOpened(WindowEvent e) {
4849

4950
});
5051
}
51-
52-
53-
5452

53+
@Override
54+
public Font getFont() {
55+
if (font == null && parent == null)
56+
font = new Font(Font.DIALOG, Font.PLAIN, 12);
57+
return super.getFont();
58+
}
59+
5560
@Override
5661
public void remove(int i) {
5762
super.remove(i);

sources/net.sf.j2s.java.core/src/swingjs/a2s/PopupMenu.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@
2020
public class PopupMenu extends JPopupMenu implements AWTPopupMenu {
2121

2222
public PopupMenu() {
23-
super();
23+
this(null);
2424
}
2525

2626
public PopupMenu(String string) {
2727
super(string);
2828
}
2929

30+
@Override
31+
public Font getFont() {
32+
// AWT default fonts are set by the peer (native OS)
33+
Font f = super.getFont();
34+
if (f == null) {
35+
setFont(f = new Font(Font.DIALOG, Font.PLAIN, 12));
36+
}
37+
return f;
38+
}
3039
@Override
3140
public int countItems() {
3241
return getComponentCount();

0 commit comments

Comments
 (0)