English 中文(简体)
Java - 使用 JTable 路径显示图像
原标题:Java - Displaying image using path from JTable

我突然发现我的节目出了问题

what it does: 倾听在 JTable 中选择行的监听器, 使用获取选中的 Row 获取单元格的内容, 如 :

 public void valueChanged(ListSelectionEvent e) {   

    int row = resultTable.getSelectedRow();
    String val = resultTable.getValueAt(row,2).toString();

    System.out.println("The value of cell 2 at selected row is: " + val);

 }

上述示例中未显示的是, JTable 的单元格 2 含有图像的本地路径, 这些路径是从本地运行的 MySQL 数据库中获取的 。

我想要它做什么: 我想用我 JTable 单元格 2 中包含的路径来在外部 JFrame 中绘制和显示图像,只要触发了被更改( 上面显示的) 的值 。

考虑到以上情况(以及我在此相当新颖的事实), 我该如何将这个 val 传递给一个图像IO. read(我假设会在一个分流类中运行? )?

感谢您抽出时间 任何帮助都是恭维的!

最佳回答

您并不真的需要 JPEG 图像的图像化图像。 只要添加此选项, 而不是您的系统. out. pripln :

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel label = new JLabel(new ImageIcon(val));
frame.setContentPane(label);
frame.pack();
frame.setVisible(true); 

如果 val 参数包含有效路径,则将显示图像。

如果图像不止一次打开一次, 请检查 ListSetectionEvent 的获取ValueIsAdjusting () 值

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签