GWT Flextable 的问题

发布于 2024-12-25 00:57:00 字数 1906 浏览 1 评论 0原文

我最近使用以下代码使用 GWT 2.4 创建了一个 FlexTable:

@uiBinder Flextable flextable;

在构造函数中,我在执行

initWidget(uiBinder.createAndBindUi(this));

之后调用 setupFlexTable() ,然后实例化 FlexTable。我错过了那部分。使用 setText() 有效。

 //Header row
    private void setupFlexTable() {
            flexTable.setText(0, 0, "Label One");
            flexTable.setText(0, 1, "Label Two");
    }

setWidget 没有显示,但这就是我使用的:

int numRows = flexTable.getRowCount();
        flexTable.setWidget(numRows, 0, new Label("Label One"));
        flexTable.setWidget(numRows, 1, new Label("Label Two"));
        flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);

这是我添加行的位置,并且此代码与 setWidget() 一起使用:

@Override
    public void setRowData(Data data) {
        int rowCount = flexTable.getRowCount() + 1;
        flexTable.setWidget((rowCount), 0, new Label(data.getDataName()));
        flexTable.getFlexCellFormatter().setRowSpan(rowCount, 0, 2);
        flexTable.setWidget((rowCount), 1, new Label(data.getData()));
        flexTable.getFlexCellFormatter().setRowSpan(rowCount, 1, 2);
    }

另外,当我使用 flexTable.setText("Label One"); 时等等...它显示,但是当我使用 setWidget() 时,它不显示?

另一个问题是我需要使该表与其上面的文件列表保持同步,但是使用 Firebug 我发现如果我动态向表中添加两行,它会显示 rowCount 为 4?当我尝试删除一行并且它到达这些空白行之一时,这会引发索引越界错误。

作为解决方法,我使用此代码来查找需要删除的行,并避免空白行的问题(显然表中插入了两个且只有两个空白行)。

int rows = flexTable.getRowCount(); 

        for(int i=0; i < rows; i++){
//Match the text in the first field in order to know the proper row to delete.
            if(flexTable.isCellPresent(i,0) && flexTable.getText(i, 0).equalsIgnoreCase(fileName)){
                flexTable.removeRow(i);
                break;
            }
        }

那么任何人都可以解释为什么 setWidget() 不显示任何内容以及为什么我为每个添加的行添加一个额外的空白行?

I recently created a flextable using GWT 2.4 using this code:

@uiBinder Flextable flextable;

In the constructor I call setupFlexTable() after I do

initWidget(uiBinder.createAndBindUi(this));

and then the flexTable is instantiated. I missed that part. Using setText() works.

 //Header row
    private void setupFlexTable() {
            flexTable.setText(0, 0, "Label One");
            flexTable.setText(0, 1, "Label Two");
    }

setWidget didn't display, but this is what I used:

int numRows = flexTable.getRowCount();
        flexTable.setWidget(numRows, 0, new Label("Label One"));
        flexTable.setWidget(numRows, 1, new Label("Label Two"));
        flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);

Here is where I add rows in and this code works with setWidget():

@Override
    public void setRowData(Data data) {
        int rowCount = flexTable.getRowCount() + 1;
        flexTable.setWidget((rowCount), 0, new Label(data.getDataName()));
        flexTable.getFlexCellFormatter().setRowSpan(rowCount, 0, 2);
        flexTable.setWidget((rowCount), 1, new Label(data.getData()));
        flexTable.getFlexCellFormatter().setRowSpan(rowCount, 1, 2);
    }

Also, when I use flexTable.setText("Label One"); etc... it displays, but when I use setWidget(), it does not?

Another issue is I need to keep this table in sync with a list of files above it, but using Firebug I see that if I add two rows dynamically to the table, it shows a rowCount of 4? This throws an index out of bounds error when I try to remove a row and it reaches one of these blank rows.

As a work-around, I use this code to find the row I need to delete and avoid the issue with the blank rows (apparently there are two and only two blank rows inserted in the table).

int rows = flexTable.getRowCount(); 

        for(int i=0; i < rows; i++){
//Match the text in the first field in order to know the proper row to delete.
            if(flexTable.isCellPresent(i,0) && flexTable.getText(i, 0).equalsIgnoreCase(fileName)){
                flexTable.removeRow(i);
                break;
            }
        }

So can anyone explain why setWidget() doesn't display anything and why I'm getting an extra blank row for each one I add?

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

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

发布评论

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

评论(3

凉墨 2025-01-01 00:57:00

您不应该在代码中实例化 FlexTable - GWT 会为您做到这一点。创建新 FlexTable 后,您正在处理一个新对象,而不是小部件中包含的对象。在您发布的代码中,有一个名为 flextable 的变量,另一个名为 flexTable - 很容易想象会发生一些混乱。

我认为一旦你正确设置了这个,你的其他问题可能会变得更加清楚。

You should not instantiate the FlexTable in your code - GWT does that for you. Once you make a new FlexTable you're working on a new object, NOT the one included in your widget. In the code you've posted you have one variable called flextable and another called flexTable - it's easy to imagine some confusion happening.

I think your other problems may become more clear once you have this set up properly.

一萌ing 2025-01-01 00:57:00

我第一次把行、列、小部件设置错了。愚蠢的语法问题。这是第一个问题的正确代码。

flexTable.setWidget(0, 0, new Label("Label One"));

这是第二个问题的答案。

这是有问题的代码行:

flexTable.getFlexCellFormatter().setRowSpan(rowCount, 0, 2);

它应该是行、列、行跨度,但我把它搞混了,所以它添加了空白行。

I got the row, column, widget setup wrong the first time. Stupid syntax issue. This is the correct code for the first issue.

flexTable.setWidget(0, 0, new Label("Label One"));

Here is the answer to the second question.

This was the offending line of code:

flexTable.getFlexCellFormatter().setRowSpan(rowCount, 0, 2);

It's supposed to be row, column, rowspan and I had it mixed up, so it was adding blank rows.

∞觅青森が 2025-01-01 00:57:00

目前,FlexTable 使用元素 td 的过时元素属性align width height 等。
自 HTML5 起,不再支持这些。 GWT 应该更改 FlexTable 和其他覆盖 HTMLTable 的类,以使用 CSS 而不是这些非常旧的元素属性!

Currently, FlexTable uses the antiquate element attributes align width height etc of the element td.
Since HTML5, these are no longer supported. GWT should change FlexTable and other classes overriding HTMLTable to use CSS instead of these very old element attributes!

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