【问题标题】:What stops my data from being displayed in a Jframe when i use HTML code in added JLabel?当我在添加的 JLabel 中使用 HTML 代码时,是什么阻止了我的数据在 Jframe 中显示?
【发布时间】:2018-05-05 20:20:09
【问题描述】:

我使用的一行代码与此一模一样:

    MyFrame.add(new JLabel("<html><body>Information to be displayed</body></html>"));

每次我执行我的项目时,JFrame MyFrame 中都不会显示任何内容,包括与 JLabel 无关的其他数据。请有人告诉我哪里出错了。

【问题讨论】:

  • (1-) Please someone should kindly tell me where i'm going wrong. - 我们怎么可能根据一行代码知道你做错了什么。 nothing displays in the JFrame MyFrame including other data not related to the JLabel. - 所以 HTML 不是问题。首先阅读 How to Use Labels 上的 Swing 教程中的部分以获取工作示例。下载演示代码并将演示代码中的标签更改为使用 HTML。
  • 感谢您提供该链接。我能够学习使用 html 的新方法。将尝试应用它们。

标签: java html swing


【解决方案1】:

我认为这是重复的问题,请参阅:
How do I put html in a JLabel in java?
HTML in JLabel not showing

测试此代码:

    JFrame MyFrame=new JFrame();
    MyFrame.setSize(300, 300);
    MyFrame.add(new JLabel("<html><font color='green'>Information to be </font> displayed <br/>it is tested</html>"));
    MyFrame.setVisible(true);

【讨论】:

  • 感谢和抱歉我的错误
  • 这些都不起作用。是否有任何与 Jframe 中的 html 不兼容的 Java 方法?我只是觉得我可能用过一个。
猜你喜欢
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多