gxt:自定义网格单元格样式

发布于 2024-12-19 14:04:02 字数 666 浏览 3 评论 0原文

我想在网格中创建自定义单元格。这不是问题。 问题:此自定义单元格中的文本样式不正确。

myColumn.setRenderer(new GridCellRenderer<TaskModel>() {
        public Object render(TaskModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<TaskModel> taskModelListStore, Grid<TaskModel> taskModelGrid) {
            VerticalPanel panel = new VerticalPanel();

            Html html = new Html("xxxx");

            Button b = new Button("xxxxxxxx");

            panel.add(html);
            panel.add(b);

            return panel;
        }
    });

为什么会发生这样的事?

样式示例

I want to create custom cell in grid. This is not a problem.
The problem: text in this custom cell has incorrect style.

myColumn.setRenderer(new GridCellRenderer<TaskModel>() {
        public Object render(TaskModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<TaskModel> taskModelListStore, Grid<TaskModel> taskModelGrid) {
            VerticalPanel panel = new VerticalPanel();

            Html html = new Html("xxxx");

            Button b = new Button("xxxxxxxx");

            panel.add(html);
            panel.add(b);

            return panel;
        }
    });

Why this happened?

Style example

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

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

发布评论

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

评论(3

刘备忘录 2024-12-26 14:04:02

您必须为自己设定风格。

 Html html = new Html("<div class=\"myStyle\">xxxx</div>");

然后在 stylesheet.css 文件中(它可能根据您的项目设置而命名不同)

.myStyle {
    //style you want
}

或内联,如果您不想编辑样式文件,例如:

 Html html = new Html("<div style=\"font-weight: bold;\">xxxx</div>");

但是我更喜欢将样式存储在代码之外的位置(如在我的第一个建议中)

You must set style for your own.

 Html html = new Html("<div class=\"myStyle\">xxxx</div>");

then in stylesheet.css file (it may be named different depending on your project setup)

.myStyle {
    //style you want
}

or inline, if you don't want edit style file, for eg.:

 Html html = new Html("<div style=\"font-weight: bold;\">xxxx</div>");

However I prefer storing styles where its place is, outside the code (as in my first suggestion)

江挽川 2024-12-26 14:04:02

如果您希望文本的样式与其他 GXT 文本的样式相同,请创建一个 GXT Text 对象并添加它。如果您想要自定义样式,那么您需要按照 @denu 的建议使用自己的 CSS。

我认为像 new Text("xxxx"); 这样的东西可能就是你想要的。

If you want the text styled the same way as other GXT text, create a GXT Text object and add that instead. If you want a custom style, then you'll need to use your own CSS as suggested by @denu.

I think something like new Text("xxxx"); might be what you want.

铃予 2024-12-26 14:04:02

@特拉维斯
有什么区别:

ColumnConfig column1 = new ColumnConfig("1", 200);
        column1.setRenderer(new GridCellRenderer<TaskModel>() {
            public Object render(TaskModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<TaskModel> taskModelListStore, Grid<TaskModel> taskModelGrid) {
                VerticalPanel panel1 = new VerticalPanel();

                panel1.add(new Html("html"));
                panel1.add(new Label("label"));
                panel1.add(new Text("text"));
                panel1.add(new Button("button"));
                return panel1;
            }
        });
        ColumnConfig column2 = new ColumnConfig("2", 200);
        column2.setRenderer(new GridCellRenderer<TaskModel>() {
            public Object render(TaskModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<TaskModel> taskModelListStore, Grid<TaskModel> taskModelGrid) {
                return new Text("text");
            }
        });

@Travis
What the difference:

ColumnConfig column1 = new ColumnConfig("1", 200);
        column1.setRenderer(new GridCellRenderer<TaskModel>() {
            public Object render(TaskModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<TaskModel> taskModelListStore, Grid<TaskModel> taskModelGrid) {
                VerticalPanel panel1 = new VerticalPanel();

                panel1.add(new Html("html"));
                panel1.add(new Label("label"));
                panel1.add(new Text("text"));
                panel1.add(new Button("button"));
                return panel1;
            }
        });
        ColumnConfig column2 = new ColumnConfig("2", 200);
        column2.setRenderer(new GridCellRenderer<TaskModel>() {
            public Object render(TaskModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<TaskModel> taskModelListStore, Grid<TaskModel> taskModelGrid) {
                return new Text("text");
            }
        });

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