Images are blank in JTable

I'm trying to add an image to a column in a JTable but they appear blank when the columns are filled.

I am overriding the getColumnClass. Here is the table declaration...

laneTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null} }, new String [] { "Lane ID", "Status", "Traffic", "Gate Arm", "Lane Indicator", "Temperature" } ) { Class[] types = new Class [] { java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class }; @Override public Class getColumnClass(int column) { if (column == 4) { return ImageIcon.class; } return Object.class; // other code; default to Object.class } });

so obviously, column 4 is my column where images are to be displayed. I am populating my table with..

for(int i = 0; i < 200; i++){ ImageIcon icon = new ImageIcon("Images/test.jpg"); laneTable.getModel().setValueAt(icon,i,4); }

The path to my images is /src/Images/test.jpg in case my pathname is somehow incorrect... Ive been dealing with this for the last week and i CANNOT figure out why these images keep showing up blank in my table.

Ideas?

edit here is what I guess is an SSCCE. No idea if it will work or not..

import javax.swing.table.DefaultTableModel; import javax.swing.*; import java.awt.event.*; import java.awt.*; public class LaneGUI extends javax.swing.JApplet implements Runnable { private Connection connection; private XMLParser xmlParser; private laneData laneData; private SiteData siteData; private Thread connectionThread; public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); ImageIcon icon = new ImageIcon("Images/test.jpg"); for(int i = 0; i < 200; i++){ laneTable.getModel().setValueAt(icon,i,4); } }); } catch (Exception ex) { ex.printStackTrace(); } } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); laneTable = new javax.swing.JTable(); laneTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null} }, new String [] { "Lane ID", "Status", "Traffic", "Gate Arm", "Lane Indicator", "Temperature" } ) { Class[] types = new Class [] { java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class }; @Override public Class getColumnClass(int column) { if (column == 4) { return ImageIcon.class; } return Object.class; // other code; default to Object.class } }); laneTable.setRowHeight(100); jScrollPane1.setViewportView(laneTable); }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addContainerGap()) ); }// </editor-fold> // Variables declaration - do not modify private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable laneTable; // End of variables declaration }

edit Tested the images in a new label, the images show correctly inside a label, but are still blank inside of the table.

-------------Problems Reply------------

A blank image might not be a path issue but a rendering issue. Look at your CellRenderer for that column. Is it using the default renderer or are you doing something special.

Try just printing out the path to make sure it is getting in the cell. Also try accessing that path from outside the JTable to make sure there is not a path issue at all.

Category:java Views:0 Time:2011-06-30

Related post

  • Swing JTable Layout: how to make table occupy complete viewport - like in eclipse IDE 2009-08-07

    In the application I am building, I will be making a few tables display different data. And I want my table to look like the tables in Eclipse IDE, like in the Problems View or the Tasks View (ignore the tree structure of the Problems View) What I am

  • Getting a JTable with a custom table model to show up in JScrollPane 2010-02-14

    I am attempting to create my own custom TableModel for my JTable (because I would like to incorporate a row of JCheckBox's into my table.) I have the JTable in a JScrollPane as well. Before I attempted to incorporate the JCheckBox and custom Abstract

  • How to Keep Track of row index when JTable has been sorted by the user? 2010-11-11

    I have a JTable which has 1st row blank. Now when I sort the table based on a column by clicking on that column then the blank row goes at the bottom. If I insert something in the blank row and do the sorting then the row is placed accordingly. How d

  • JTable does not show anything? 2010-12-17

    here is my entire class. I read data from a text file, put them into an aeeaylist. then from that array list i want to show the data on a JTable, when the specific method is called.But is doesnt show anything /* * To change this template, choose Tool

  • JTable HTML Font Display Problem with JRE 6U24 2011-04-08

    In my JApplet program,I'd like to make the color of one cell of JTable to BLUE. Though there has many methods to do it.One method I think easy is to use HTML tag. But it only works well when firstly access the JApplet with JRE 6u24. operation as foll

  • Dynamically change the cell height in JTable with a GridBagLayout 2011-05-05

    I run into a problem where I have a JTable laid out using GridBagLayout manager and the number of rows in the table is not fixed. I intend to fill the space assigned to the table with all its cells, however there is a big blank (and white) space betw

  • Need to display next level text in a jtable on double clicking the "Entering thread" (Thread name) 2011-06-02

    I have log file that looks similar to the one below. I need to display this info on a gui. Also find the table attached. When i double click the "Entering Thread ID=.." in the table, i am supposed to display the next level of all the "Enterings" of t

  • Problems with JTable and JScrollpane size 2011-06-04

    I have a JScrollPane with a JTable in it. In the JTable I have initially 3 rows. Later on rows get added. The default JTable with my 3 rows is ugly because JScrollPane calls getPreferredScrollableViewportSize from the client (JTable) and the return v

  • Inserting an Image into a JTable 2011-06-24

    I'm having an issue inserting images into a JTable. Ive searched and found there are 2 ways. You can either override the getcolumnclass of the tablemodel or create your custom tablecellrender. I chose to make my own cell renderer with this code: publ

  • JTable not showing output 2011-07-01

    Here's my code: private void show(java.awt.event.ActionEvent evt) { Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName = "phone"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "sc

  • JTable how prepareEditor works 2011-08-12

    I don't understand how prepareEditor works, I'm not able set visibility rules for prepareRenderer with Action from prepareEditor, as I captured in attached Image rules for 1.st row works as I expected, other TableCells are un-visible if JCheckBox isn

  • Multiple cell renderers for a column in a JTable? 2011-10-07

    Let's say I have the following JTable, which is displayed as soon as a button is pressed: | Name ------+------------ True | Hello World False | Foo Bar True | Foo False | Bar I want to render the cells that were initially true to a JCheckBox, and all

  • Action listner to JTable that been reset 2011-11-15

    I'm having issue with Action Listener of a JTable that being updated according the radioButtons. I created a blank table and just re-update according to which button is selected. The only issue I have is that the action Listener are not being updated

  • Refresh JTable after executing SQL UPDATE statement 2011-12-28

    I created a JTable and defined MyTableModel in order to populate this table from MySQL DB. However, the problem is that when I execute UPDATE statement, then an additional row is included in JTable (but not in MySQL DB). How should I update my code t

  • how to set an image for jtable fixed column, when i am running, it's getting an image path only 2012-02-01

    I created a program to set an imageIcon in jtable fixed column, i created a jtable and getting a database records, then set a first column as fixed column. i set an image icon in fixed column. when i am compiling this program, i am getting only a pat

  • Add Image in JTable without using renderer 2012-02-08

    I need to add image in Jtable cell without using TableCellRenderer.If i Use the following code means it display the name (string) in that particular cell instead of image.how to do this?. ImageIcon Icon= new ImageIcon("Blank.gif"); table.setValueAt(I

  • Image display in JTable cell 2012-02-09

    I use the following program for creating JTable using java class. If I get the images for warnIcon,infoIcon from optionpane it displays properly. However, if I add image from my system it doesn't display in table. A blank space is displayed instead o

  • how to set the image in Jtable cell using renderer? 2012-02-10

    Am using the following code for display the image in JTable cell.I have two questions for add image in jtable cell. 1.if i click the first row in the table ,the "Pointer.gif"image will display in that row.when i click the second row the "pointer .gif

  • JTable load values on change, display progressbar while loading 2012-04-11

    So i am working with a JTable, It has Columns A-K. with A and B being the only editable ones. If someone edits an empty row in A, I make an API call to get B then i make a DB call to get all rows where B exists.If someone edits an empty row in B, i m

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.111 (s). 11 q(s)