在特定列中制作可jt的单元
我正在使用Swing在Java中创建GUI。我使用看起来像这样的jtable。 。
这就是我创建我的JTable的方式。
this.tableModel = new DefaultTableModel(
new Object[][] { },
new String[] {"ID", "Nazov", "Naplnena kapacita / kapacita", "Popis"}
);
this.table1.setModel(this.tableModel);
我使用this.tablemodel.addrow();
添加数据。 有没有办法使我的表的最后一列可以滚动?
I'm creating GUI in java using swing. I use JTable that looks like this.
I need to make cells of last column("Popis") to be scrollable as there will be description so String containing this description has variable lenght for each row.
This is how I created my JTable.
this.tableModel = new DefaultTableModel(
new Object[][] { },
new String[] {"ID", "Nazov", "Naplnena kapacita / kapacita", "Popis"}
);
this.table1.setModel(this.tableModel);
I add data to table using this.tablemodel.addRow();
Is there a way to make cells of last column of my table scrollable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将滚动组件嵌入JTable将很困难和尴尬。显示长单元格值的一种常见方法是使单元的工具提示(悬停文本)显示完整值:(
对象
是java.util.objects类。)It would be difficult and awkward to embed a scrolling component inside a JTable. A common approach to showing long cell values is to make the cell’s tooltip (hover text) display the full value:
(
Objects
is the java.util.Objects class.)可以通过创建扩展
AbstractCelleditor
并实施TableCelleDitor
的私人类来解决。然后创建并自定义滚动条。这是示例。It can be solved by creating private class that extends
AbstractCellEditor
and implementsTableCellEditor
. Then create and customize the scrollbar. Here is example.