您可以设置JTable的单元格溢出吗? [英] Can you set the cells of JTable to spill over?

查看:91
本文介绍了您可以设置JTable的单元格溢出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JTable上模仿一些Excel电子表格功能,特别是我一直所说的单元格溢出或单元格溢出.当您用比单元格设置为宽的宽度填充文本时,会发生这种情况.如果右边的单元格中没有文本,则这些单词只会继续进入下一个单元格,甚至更远.

I'm trying to imitate some Excel spreadsheet functionality on my JTable, specifically what I've been calling cell spillover or cell overflow. This occurs when you fill a cell with text with a wider width than the cell is set to. If there is no text in the cell to its right, the words simply keep going into the next cell and beyond.

我觉得可以通过TableCellRenderer以某种方式完成此操作,但我不知道如何做到. 任何帮助将不胜感激

I feel like this would be accomplished somehow with TableCellRenderer, but I do not know how. Any help would be much appreciated

推荐答案

否,TableCellRenderer无法跨越单元格.作为替代方案,请考虑以下因素:

No, a TableCellRenderer cannot span cells. As alternatives, consider these:

  • TablePopupEditor, a custom TableCellEditor, can be adapted to serve as a renderer.

A ListSelectionListener,显示在此处,可以添加到相邻组件以显示所选行的详细信息,也许使用JScrollPane.

A ListSelectionListener, shown here, can be added to an adjacent component in order to display details of the selected row, perhaps using a JScrollPane.

这篇关于您可以设置JTable的单元格溢出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆