I am making a database search GUI for a CCG. I have a large GUI with JTextFields, JComboBoxes, JButtons, etc. When the user presses search, the program queries the MySQL database based on input from the user and displays the results in a JTable. The search is working great and returning the correct information. However, the final column of the database is a String that contains the file name of an image (png) for each record. I am having trouble getting the table to display the last column as an Image.
try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + dbName, dbUsername, dbPassword); Statement sqlState = conn.createStatement(); String selectStuff = "SELECT * FROM ..."; rs = sqlState.executeQuery(selectStuff); Object[] tempRow; // -------------------------------------------------------------- // ImageIcon testIcon = new ImageIcon("test.png"); // -------------------------------------------------------------- while(rs.next()){ tempRow = new Object[] {rs.getString(3), rs.getString(4), rs.getString(10), rs.getString(6), rs.getString(5), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17), rs.getString(18), rs.getString(19), rs.getString(42) }; dTableModel.addRow(tempRow); } }
The final column "rs.getString(42)" is the String that I want to turn into an ImageIcon.
Even when I try to manually set the value as an Icon by adding...
...and changing...ImageIcon testIcon = new ImageIcon("test.png");
...I still can't get it to work. The last column of the table just spits out "test.png".rs.getString(42) to testIcon
I've searched all over the internet and tried overriding the getColumnClass, but I had no luck there either.
I'm able to read in the String of the filename from MySQL. How do I get Java to recognize/convert this to an ImageIcon?