更新时间:2023-12-03 12:24:04
您需要添加 JLabel
。***扩展 JPanel
而不是 JComponent
,因为它有一个默认的布局管理器,无需设置组件大小即可显示任何添加的组件。 paintComponent
用于自定义绘画BTW。
You need to add the JLabel
. Also better to extend JPanel
instead of JComponent
as it has a default layout manager and will make any added components appear without the need to set component sizes. paintComponent
is used for custom painting BTW.
public class Component1 extends JPanel {
Component1() {
JLabel label = new JLabel("<html>Some Text</html>");
add(label);
}
}