I have a JLabel that I have set the custom font, "BP Diet" to it. If I add this to a JFrame, the text appears fine, but as soon as I change the layout of the JFrame to FlowLayout, the top of the text appears cut off. This same problem occurs when you add the JLabel to a JPanel and add that to the JFrame. I have the font available at http://www.hichris.com/more/files/BPdiet.otf
Here is the code below:
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.net.URL;
public class FontSizeTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(
"AaBbCcDdEeFfGgHhIiJjKk");
label.setFont(createFont());
frame.add(label);
frame.pack();
frame.setMinimumSize(frame.getMinimumSize());
frame.setVisible(true);
}
static Font createFont() {
Font customFont = null;
try {
URL url = new URL("http://www.hichris.com/more/files/BPdiet.otf");
InputStream is = url.openStream();
customFont = Font.createFont(Font.TRUETYPE_FONT, is);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(customFont);
} catch (Exception e) {
e.printStackTrace();
}
return customFont.deriveFont(25f);
}
}
As it should appear
As it appears after pack()
Bigger view pointing out the dots above i & j
Any help is appreciated!