gpt4 book ai didi

java - JXTable背景图像不渲染

转载 作者:行者123 更新时间:2023-11-30 04:54:47 24 4
gpt4 key购买 nike

我正在尝试生成一个带有背景图像的 JXTable(文本也可以)。这是我的扩展 JXTable 类:

public class JXTableWithBackground extends JXTable{

ImageIcon image;
public JXTableWithBackground(ParticipantTableModel pTableModel, ImageIcon image){
super(pTableModel);
this.image=image;
}
public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
Component c = super.prepareRenderer( renderer, row, column);
// We want renderer component to be transparent so background image is visible
if( c instanceof JComponent )((JComponent)c).setOpaque(false);
return c;
}

@Override
public void paint(Graphics g) {
//draw image in centre
final int imageWidth = image.getIconWidth();
final int imageHeight = image.getIconHeight();
final Dimension d = getSize();
final int x = (d.width - imageWidth)/2;
final int y = (d.height - imageHeight)/2;
g.drawImage(image.getImage(), x, y, null, null);
super.paint(g);
}

图像没有显示 - 我只看到空白。有什么想法吗?

最佳答案

供将来引用:

问题似乎是表格本身没有透明渲染。将表格本身设置为 opaque = false 会有所帮助。

关于java - JXTable背景图像不渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8883105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com