我是 JLabel
的新手,我想知道是否可以在图像上的特定坐标 (x,y) 中设置文本。
像这样:
所以文本是“HI”
label.setText("HI");
label.setIcon(icon);
我试图说 label
包含图像和文本,但我想将其定位在特定位置,如上图所示。
我不想使用label.setHorizontalTextPosition(i);
或setVerticalTextPosition(i);
抱歉我的英语不好 提前致谢 ^ ^
最佳答案
通过重写paintComponent
方法,可以在任何位置绘制文本。
JLabel label = new JLabel(icon) {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("Hi", 10, 10); //these are x and y positions
}
};
关于java - JLabel文本位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36271536/