Pregunta

First off here is my code:

public static Font kingThing;

public static void main(String[] args) throws IOException {
    try {
        /** Substance look and feel */
        UIManager.setLookAndFeel(new NimbusLookAndFeel());
    } catch (UnsupportedLookAndFeelException ulafe) {
        Loader loader = new Loader();
        loader.doFrame();
    }
    Start Loader = new Start();
    Loader.setVisible(true);
    DirectBufferHelper.oggstream().connect();
}

public Start() throws IOException {
    /** The name of the frame */
    super("Client Launcher");
    try {

    getContentPane().setBackground(Color.BLACK);
    setBackground(Color.BLACK);

    /** Creates and adds the main configurations of the frame */
    BufferedImage image39 = ImageIO.read(getClass().getResourceAsStream("\\jaggl\\igs\\39.png"));

    this.setIconImage(image39);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(new Dimension(launcherWidth, launcherHeight));
    this.setLocationRelativeTo(null);
    this.setResizable(false);
    getContentPane().setLayout(null);
    paintAll();
    } catch (IOException e) {
        System.out.println(e);
    }
    try {
          InputStream in = getClass().getResourceAsStream("Kingthings Petrock.ttf");
          kingThing = Font.createFont(0, in);
        } catch (Throwable e) {
          e.printStackTrace();
        }
}

&

/**
         * Loaders main page Username Display
         */
        loggedInAsDisplay = new JLabel(getloggedInAs());
        loggedInAsDisplay.setBounds(305, 68, 200, 20);
        loggedInAsDisplay.setForeground(Color.LIGHT_GRAY);
        loggedInAsDisplay.setFont(kingThing);
        getContentPane().add(loggedInAsDisplay);

Now when I start up the frame the text displays as a dot. The username is set to the players username. for instance I logged into my test account & my main account. & the following displays:

The dot is the "text"........?

How do I get it to display the actual text not just a dot. Before I added the font it correctly displayed the text.

¿Fue útil?

Solución

What you have creates a font with point size of 1, so you have to derive a font with a larger point size, instead try:

kingThing = Font.createFont(Font.TRUETYPE_FONT, in).deriveFont(36f);

Here the actual docs that specify this, and the text:

createFont

Returns a new Font using the specified font type and input data. The new Font is created with a point size of 1 and style PLAIN. This base font can then be used with the deriveFont methods in this class to derive new Font objects with varying sizes, styles, transforms and font features. T

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top