【问题标题】:Java Font displaying as a single dotJava 字体显示为单个点
【发布时间】:2013-12-05 04:52:29
【问题描述】:

首先是我的代码:

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);

现在,当我启动框架时,文本显示为一个点。用户名设置为玩家用户名。例如,我登录了我的测试账户和我的主账户。 & 以下显示:

如何让它显示实际文本而不仅仅是一个点。在我添加字体之前,它正确显示了文本。

【问题讨论】:

    标签: java swing fonts jlabel nimbus


    【解决方案1】:

    你所创建的字体大小为 1,所以你必须派生一个更大的字体,而不是尝试:

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

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

    创建字体

    使用指定的字体类型和输入数据返回一个新字体。新字体使用 1 磅大小和样式 PLAIN 创建。然后可以将此基本字体与此类中的 derivedFont 方法一起使用,以派生具有不同大小、样式、变换和字体特征的新 Font 对象。 T

    【讨论】:

    • 你设置等于 kingThings,那个函数返回一个字体,它不会改变原来的
    • 是的。你解决了我的问题,我想我在错误的地方添加了它(facepalm)。我把它放在我的 setFont 上面。我替换了 Start 方法中的那个,一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多