调整 JTable-grid 的大小和颜色并使单元格可调整大小

发布于 2024-08-22 08:40:42 字数 59 浏览 5 评论 0原文

如何调整JTable中网格的大小和颜色以及如何设置JTable使得列或行的长度可以通过拖动来增加和减少?

How to adjust the size and colour of grid in JTable and how to set JTable so that length of column or row can be increased and decreased by dragging it?

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

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

发布评论

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

评论(1

吾性傲以野 2024-08-29 08:40:42

您可以使用 setGridColor 设置网格的颜色。

要让用户调整列宽,请使用 getTableHeader()setResizingAllowed(true)

没有对调整行大小的开箱即用的支持,这个帖子可能会有所帮助。

更多信息:

    // grid color
    jTable1.setGridColor(Color.BLUE);

    // columns resizable
    jTable1.getTableHeader().setResizingAllowed(true);

    // initial width of column 1
    jTable1.getColumnModel().getColumn(1).setPreferredWidth(400);

    // height of al columns
    jTable1.setRowHeight(50);

    // height of column 2
    jTable1.setRowHeight(2, 25);

You can use setGridColor to set the color of the grid.

To let the user adjust column width, use getTableHeader().setResizingAllowed(true).

There is no out-of-the-box support for resizing rows, this post could help.

Some more information:

    // grid color
    jTable1.setGridColor(Color.BLUE);

    // columns resizable
    jTable1.getTableHeader().setResizingAllowed(true);

    // initial width of column 1
    jTable1.getColumnModel().getColumn(1).setPreferredWidth(400);

    // height of al columns
    jTable1.setRowHeight(50);

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