如何在java swing中获取要在JTable中显示的图像 [英] How do I get a an image to display in JTable in java swing

查看:187
本文介绍了如何在java swing中获取要在JTable中显示的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个jTable,并将ImageIcon对象放在其中一列中。我想知道如何让它显示图像而不是图像名称作为字符串。

I have created a jTable and have put an ImageIcon objects in one of the columns. I would like to know how I can get it to display the image rather than the image name as a string.

谢谢

推荐答案

您必须实现 TableCellRenderer 并为相应的列设置它。

You have to implement a TableCellRenderer and set it for the respective column.

A TableCellRenderer 只有一个方法返回 Component 以显示在表格单元格中。但是,您可能需要在要显示图像时调整行高,因为行不会自动调整其内容。

A TableCellRenderer has just one method which returns a Component to display in a table cell. However, you probably need to adjust the row heights when you want to display images, since the rows won't adjust automatically to their content.

有关如何使用自定义渲染器的信息您可以参考 Java教程

For how to use custom renderers you can refer to the Java Tutorials.

这篇关于如何在java swing中获取要在JTable中显示的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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