您好,是否可以在 titledBorder 的标题中放置一个图标,例如以下代码:
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class TitledExample extends JPanel {
public TitledExample() {
super(true);
this.setLayout(new GridLayout(1, 1, 5, 5));
JLabel label = new JLabel("Titled Border");
label.setHorizontalAlignment(JLabel.CENTER);
TitledBorder titled = new TitledBorder("Image here ?? Title");
label.setBorder(titled);
add(label);
}
谢谢,干杯
尝试子类化TitledBorder
,并覆盖paintBorder
method:
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
super.paintBorder(c, g, x, y, width, height);
// Now use the graphics context to draw whatever needed
g.drawImage(img, xImageOffset, yImageOffset, imgWidth, imgHeight, observer);
}
不太确定这是完全正确的方法调用,但您明白了;一旦您有权访问Graphics
对象,你几乎可以画任何你需要的东西。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)