为什么我会收到“找不到符号”的信息Java 中的错误?

发布于 2024-12-13 17:47:11 字数 701 浏览 1 评论 0原文

@Override
public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected,
        boolean hasFocus, int row, int col) {

    // *** here  *** 
    Component c = super.getTableCellRendererComponent(table, value, isSelected, 
               hasFocus, row, col); 

    // Formatting here
    return c;
}

我在指定的行中收到错误。它说“找不到符号”,但我不知道真正的问题是什么。


已更新

@martinusadyh

恐怕该类太大,因此不允许我将其粘贴到此处。

@ Hovercraft Full Of Eels

这是 Netbeans 中的错误
https://i.sstatic.net/R4fv3.jpg

@Henery

这不是我的课。我只是实现一个接口方法。

@Override
public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected,
        boolean hasFocus, int row, int col) {

    // *** here  *** 
    Component c = super.getTableCellRendererComponent(table, value, isSelected, 
               hasFocus, row, col); 

    // Formatting here
    return c;
}

I'm getting an error in the indicated line. It says "cannot find symbol" but I can't realize what the real problem is.


Updated

@martinusadyh

I'm afraid the class is too big so it doesn't allow me to paste it here.

@ Hovercraft Full Of Eels

here's the error in Netbeans
https://i.sstatic.net/R4fv3.jpg

@Henery

It's not my class. I'm only implementing an interface method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘和柠 2024-12-20 17:47:11

那个类不是我的,我只是实现一个接口的方法。

那么您的父类 superObject 并且没有方法 getTableCellRendererComponent。您要么必须扩展一个合适的类,要么在不调用不存在的方法的情况下相处。

It's not mine that class, i'm only implementing an interface's method.

Then your parent class super is Object and has no method getTableCellRendererComponent. You either have to extend a suitable class or get along without calling non-existing methods.

雨后彩虹 2024-12-20 17:47:11

您必须扩展DefaultTableCellRenderer而不是实现TableCellRenderer


注意DefaultTableCellRenderer其方法getTableCellRendererComponent返回this。这意味着调用 super.getTableCellRendererComponent(); 就足够了,无需将其分配给局部变量。因为局部变量等于this。也许我的解释太难了:例子。

public class MyTableCellRenderer extends DefaultTableCellRenderer
{

    @Override
    public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int col) {

        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); 

        // Formatting here
        setIcon(myCustomIcon);
        setText(myCustomText);

        return this;
    }

}

You have to extends DefaultTableCellRenderer instead of implements TableCellRenderer.


Note: DefaultTableCellRenderer its method getTableCellRendererComponent returns this. This means that it's enough to call the super.getTableCellRendererComponent(); without assigning it to a local variable. Because the local variable equals this. Maybe my explanation is too difficult: example.

public class MyTableCellRenderer extends DefaultTableCellRenderer
{

    @Override
    public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int col) {

        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); 

        // Formatting here
        setIcon(myCustomIcon);
        setText(myCustomText);

        return this;
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文