JTable with ImageIcons does not react to even handling

Hi.
I have a populated JTable with ONLY ImageIcons in it. I need to generate event responses on mouseClicks. However, any event listener I associate with this, nothing seems to be happening.
(Somehow, I'm guess the ImageIcons - which are rendered on a JLabel, are/is the source of all troubles!!)
The code is below :
import java.io.File;
import java.awt.Point;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
*     Entry point for the Images Table.
*     @author Raj Gaurav
public class SpecialCharacterDialog extends JDialog{
     String collectionString[] = null;
     ImageIcon suite[] = null;
     public SpecialCharacterDialog() {
          Container contentPane = getContentPane();
          //     Create the Table Model and create the Table from the model
          MyTableModel model = new MyTableModel();
          JTable table = new JTable(model);
          table.setDefaultRenderer(ImageIcon.class, new CustomCellRenderer());
          table.setCellSelectionEnabled(true);
          table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
} else {
int selectedRow = lsm.getMinSelectionIndex();
System.out.println("Row " + selectedRow
+ " is now selected.");
          //     Add the table to the contentPane
          JScrollPane pane = new JScrollPane(table);
          contentPane.add(pane);
*     This class contains all the DATA information, the ImageIcons
*     needed for display.
class SymbolCollection {
     final static int NUMBER_OF_COLUMNS = 15;
     private String collectionString[] = null;
     private ImageIcon suite[] = null;
     *     Constructor : Initialises all the ImageIcon and their Names.
     public SymbolCollection() {
          File f = new File("C:\\Test\\Images");
          collectionString = f.list();
          int numberOfImages = collectionString.length;
          suite = new ImageIcon[numberOfImages];
          for(int i = 0;i < numberOfImages; i++) {
               suite[i] = new ImageIcon("C:\\Test\\images" + File.separator + collectionString);
     *     Returns the total number of images in "images" folder.
     public int getTotalNumberOfImages() {
          return suite.length;
     *     Returns the target ImageIcon.
     public ImageIcon getImageIconAt(int number) {
          return suite[number];
     *     Returns the target ImageIcon Name.
     public String getImageIconNameAt(int number) {
          return collectionString[number];
     *     Returns an array of ALL the ImageIcons available.
     public ImageIcon[] getImageIcons() {
          return suite;
     *     Returns an array of ALL the ImageIcon names available
     public String[] getImageIconNames() {
          return collectionString;
     *     Returns TRUE for all cells
     public boolean isEditable(int row, int col) {
          return true;
*     Defines the table model for the tabel.
class MyTableModel extends AbstractTableModel {
     private SymbolCollection collection = null;
     private Object data[][] = null;
     *     Constructor for the TableModel. Initialises the "data" field for table.
     public MyTableModel() {
          int countOfImages = 0;
          collection = new SymbolCollection();
          data = new Object[getRowCount()][SymbolCollection.NUMBER_OF_COLUMNS];
          for(int i = 0; i < getRowCount(); i++) {
               for(int j = 0; j < SymbolCollection.NUMBER_OF_COLUMNS; j++) {
                    if(countOfImages == collection.getTotalNumberOfImages()) {
                         break;
                    data[i][j] = collection.getImageIconAt(countOfImages);
                    countOfImages++;
     *     Returns the number of rows for this table.
     *     It is calculated as : TotalNumber/NumberOfColumns if remainder is ZERO or,
     *                              TotalNumber/NumberOfColumns + 1 if not.
     public int getRowCount() {
          int numberOfRows = collection.getTotalNumberOfImages()/SymbolCollection.NUMBER_OF_COLUMNS;
          if(numberOfRows == 0) {
               return numberOfRows;
          else {
               return numberOfRows + 1;
     *     Returns the number of Columns for this table
     public int getColumnCount() {
          return SymbolCollection.NUMBER_OF_COLUMNS;
     *     Returns the CLASS data type for this table
     public Class getColumnClass(int col) {
          return collection.getImageIconAt(0).getClass();
     *     Returns the table data at (row, col).
     public Object getValueAt(int row, int col) {
          return data[row][col];
*     Renders the table to display images in individual cells
class CustomCellRenderer extends JLabel implements TableCellRenderer {
     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
          setIcon((ImageIcon)value);
          return this;

Hi.
I have a populated JTable with ONLY ImageIcons in it. I need to generate event responses on mouseClicks. However, any event listener I associate with this, nothing seems to be happening.
(Somehow, I'm guess the ImageIcons - which are rendered on a JLabel, are/is the source of all troubles!!)
The code is below :
import java.io.File;
import java.awt.Point;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
*     Entry point for the Images Table.
*     @author Raj Gaurav
public class SpecialCharacterDialog extends JDialog{
     String collectionString[] = null;
     ImageIcon suite[] = null;
     public SpecialCharacterDialog() {
          Container contentPane = getContentPane();
          //     Create the Table Model and create the Table from the model
          MyTableModel model = new MyTableModel();
          JTable table = new JTable(model);
          table.setDefaultRenderer(ImageIcon.class, new CustomCellRenderer());
          table.setCellSelectionEnabled(true);
          table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
} else {
int selectedRow = lsm.getMinSelectionIndex();
System.out.println("Row " + selectedRow
+ " is now selected.");
          //     Add the table to the contentPane
          JScrollPane pane = new JScrollPane(table);
          contentPane.add(pane);
*     This class contains all the DATA information, the ImageIcons
*     needed for display.
class SymbolCollection {
     final static int NUMBER_OF_COLUMNS = 15;
     private String collectionString[] = null;
     private ImageIcon suite[] = null;
     *     Constructor : Initialises all the ImageIcon and their Names.
     public SymbolCollection() {
          File f = new File("C:\\Test\\Images");
          collectionString = f.list();
          int numberOfImages = collectionString.length;
          suite = new ImageIcon[numberOfImages];
          for(int i = 0;i < numberOfImages; i++) {
               suite[i] = new ImageIcon("C:\\Test\\images" + File.separator + collectionString);
     *     Returns the total number of images in "images" folder.
     public int getTotalNumberOfImages() {
          return suite.length;
     *     Returns the target ImageIcon.
     public ImageIcon getImageIconAt(int number) {
          return suite[number];
     *     Returns the target ImageIcon Name.
     public String getImageIconNameAt(int number) {
          return collectionString[number];
     *     Returns an array of ALL the ImageIcons available.
     public ImageIcon[] getImageIcons() {
          return suite;
     *     Returns an array of ALL the ImageIcon names available
     public String[] getImageIconNames() {
          return collectionString;
     *     Returns TRUE for all cells
     public boolean isEditable(int row, int col) {
          return true;
*     Defines the table model for the tabel.
class MyTableModel extends AbstractTableModel {
     private SymbolCollection collection = null;
     private Object data[][] = null;
     *     Constructor for the TableModel. Initialises the "data" field for table.
     public MyTableModel() {
          int countOfImages = 0;
          collection = new SymbolCollection();
          data = new Object[getRowCount()][SymbolCollection.NUMBER_OF_COLUMNS];
          for(int i = 0; i < getRowCount(); i++) {
               for(int j = 0; j < SymbolCollection.NUMBER_OF_COLUMNS; j++) {
                    if(countOfImages == collection.getTotalNumberOfImages()) {
                         break;
                    data[i][j] = collection.getImageIconAt(countOfImages);
                    countOfImages++;
     *     Returns the number of rows for this table.
     *     It is calculated as : TotalNumber/NumberOfColumns if remainder is ZERO or,
     *                              TotalNumber/NumberOfColumns + 1 if not.
     public int getRowCount() {
          int numberOfRows = collection.getTotalNumberOfImages()/SymbolCollection.NUMBER_OF_COLUMNS;
          if(numberOfRows == 0) {
               return numberOfRows;
          else {
               return numberOfRows + 1;
     *     Returns the number of Columns for this table
     public int getColumnCount() {
          return SymbolCollection.NUMBER_OF_COLUMNS;
     *     Returns the CLASS data type for this table
     public Class getColumnClass(int col) {
          return collection.getImageIconAt(0).getClass();
     *     Returns the table data at (row, col).
     public Object getValueAt(int row, int col) {
          return data[row][col];
*     Renders the table to display images in individual cells
class CustomCellRenderer extends JLabel implements TableCellRenderer {
     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
          setIcon((ImageIcon)value);
          return this;

Similar Messages

  • On my MacBook with Lion Safari does start, does not react immediately after trying to open it. Installing a new Safari does not help. Removing parts of Safari in the Library did not help. Where can I find and remove all components (LastSession ...)?

    How can I reset Safari with all components? On my MacBook with Lion, Safari does not start, does not react immediately after trying to open it. Installing a new Safari does not help. Removing parts of Safari in the Library does not help. Where can I find and remove all components as LastSession and TopSites?

    The only way to reinstall Safari on a Mac running v10.7 Lion is to restore OS X using OS X Recovery
    Instead of restoring OS X in order to reinstall Safari, try troubleshooting extensions.
    From the Safari menu bar click Safari > Preferences then select the Extensions tab. Turn that OFF, quit and relaunch Safari to test.
    If that helped, turn one extension on then quit and relaunch Safari to test until you find the incompatible extension then click uninstall.
    If it's not an extensions issue, try troubleshooting third party plug-ins.
    Back to Safari > Preferences. This time select the Security tab. Deselect:  Allow plug-ins. Quit and relaunch Safari to test.
    If that made a difference, instructions for troubleshooting plugins here.
    If it's not an extension or plug-in issue, delete the cache.
    Open a Finder window. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following
    ~/Library/Caches/com.apple.Safari/Cache.db
    Click Go then move the Cache.db file to the Trash.
    Quit and relaunch Safari to test.

  • I have updated my Iphone5 with new IOS6 - now the screen/display does not react to my taps on screen as in i cant tap in my pin to start???

    I have updated my Iphone5 with new IOS6 - now the screen/display does not react to my taps on screen as in i cant tap in my pin to startup???

    I have updated my Iphone5 with new IOS6 - now the screen/display does not react to my taps on screen as in i cant tap in my pin to startup???

  • I can pair my iPhone 4 with my MacBook and my Macbook Pro but they will not connect. My iPhone keeps telling me it does not support this even with bluetooth turned on.The devices section keeps searching all the time

    I can pair my iPhone 4 with my MacBook and my Macbook Pro but they will not connect. My iPhone keeps telling me it does not support this even with bluetooth turned on.The devices section keeps searching all the time. Is this an antenna problem? Or something else ?

    Your iphone is right, it is not supported. The iphone's bluetooth protocols do not include file transfer, but are intendes only for headsets, stereo headphones, cars, and keyboards.

  • Adobe Audition does not playback any audio file. He opens it but does not react on the play key.

    Adobe Audition CC does not playback any audio file. He opens it but does not react on the play key. It is after use audio hardware usb wi-fi headphone and return to build-it out. The program don't react now.
    I see problem:
    I am unable to get playback at all in CS6 on Mac. The play button or spacebar will not move the playhead or make sound come out of the foamy things with the magnets. The play button toggles back and forth between green and white, but it isn't working. This is true in both multi track and waveform view.
    Anyone have ideas on what the issue could be? Thanks!
    Some Info:
    MacBook Pro 2.2 i7, 16GB RAM, 512GB SSD
    Mac OS 10.8.3
    Audition CS6 5.0.2 Build 5
    and reply:
    Best bet would be to go into Preferences > Audio Hardware, verify your input and output devices are correct, and probably switch your Master Clock to the opposite setting.  If that fails, we can continue troubleshooting.
    I have the same problem as the author writes. But these actions do not help

    Unfortunately I believe that requires purchasing the new version, and I do
    not have budget approval for such a purchase.
    On Tue, Jan 27, 2015 at 11:34 AM, Charles VW <[email protected]>

  • I had to reload ice age village and now my progress does not show up even though it is still in game center

    I had to reload ice age village and now my progress does not show up even though it is still in game center

    Your settings are not saved. try with new profile.
    Create a new profile as a test to check if your current profile is causing the problems. <br>
    See '''Creating a profile''':
    *https://support.mozilla.org/kb/profile-manager-create-and-remove-firefox-profiles
    *http://kb.mozillazine.org/Standard_diagnostic_-_Firefox#Profile_issues
    If the new profile works then you can transfer files from a previously used profile to the new profile, but be cautious not to copy corrupted files to avoid carrying over the problem <br>
    '''Profile Backup and Restore'''
    *http://kb.mozillazine.org/Profile_backup
    *https://support.mozilla.org/en-US/kb/back-and-restore-information-firefox-profiles
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • My phone turns off and does not turn on, even i tries holding power button n home button for few min.... its shows nothing. i connect it to the computer n it doesnt show in itunes.  plz repl wats the prblm wid it

    my phone turns off and does not turn on, even i tries holding power button n home button for few min.... its shows nothing. i connect it to the computer n it doesnt show in itunes.  plz reply wats the prblm wid it

    Hi kamalkumar,
    I'm sorry to hear you are having issues with your iPhone. 
    The article below will provide some troubleshooting steps for this issue:
    iPhone: Hardware troubleshooting
    Will not turn on, will not turn on unless connected to power, or unexpected power off
    Verify that the Sleep/Wake button functions. If it does not function, inspect it for signs of damage. If the button is damaged or is not functioning when pressed, seek service.
    Check if a Liquid Contact Indicator (LCI) is activated or there are signs of corrosion. Learn about LCIs and corrosion.
    Connect the iPhone to the iPhone's USB power adapter and let it charge for at least ten minutes.
    After at least 15 minutes, if:
    The home screen appears: The iPhone should be working. Update to the latest version of iOS if necessary. Continue charging it until it is completely charged. Then unplug the phone from power. If it immediately turns off, seek service.
    The low-battery image appears, even after the phone has charged for at least 20 minutes: See "iPhone displays the low-battery image and is unresponsive" symptom in this article.
    Something other than the Home screen or Low Battery image appears, continue with this article for further troubleshooting steps.
    If the iPhone did not turn on, reset it while connected to the iPhone USB power adapter.
    If the display turns on, go to step 4.
    If the display remains black, go to next step.
    Connect the iPhone to a computer and open iTunes. If iTunes recognizes the iPhone and indicates that it is in recovery mode, attempt to restore the iPhone. If the iPhone doesn't appear in iTunes or if you have difficulties in restoring the iPhone, see this article for further assistance.
    If restoring the iPhone resolved the issue, go to step 4. If restoring the iPhone did not solve the issue, seek service.
    I hope this information helps ....
    Have a great day!
    - Judy

  • IPhoto does not react

    hi! i used i photo since february and it never worked really stable since the beginning, but with the updates i somehow managed. now since 2 weeks when i open it, it just shows the working sign and nothing happens und till i open the "close immidiately" button and this always shows "does not react".
    I downloaded picassa and after the second time the same thing happened there. i thought that the mac runs so stable, especially on photos and design programs!! i am quite disappointed!!

    Try this:  launch iPhoto with the Option key held down and create a new, test library.  Import some photos and check to see if the same problem persists. If the problem goes away with the new, test ibrary then the problem lies with your current library.
    In that case make a temporary, backup copy (if you don't already have a backup copy)  of your library and apply the three fixes in order as necessary.
    Fix #1
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your HD/User/Home()/ Library/Preferences folder.
    2 - delete iPhoto's cache file, Cache.db, that is located in your HD/User/Home()/Library /Caches/com.apple.iPhoto folder. 
    3 - launch iPhoto and try again.
    NOTE: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto.  You'll also have to reset the iPhoto's various preferences.
    Fix #2
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Select the options identified in the screenshot. 
    Fix #3
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

  • Screen does not react

    I opened the box to my brand new Ipad 2. It turns on and connects fine. The problem is that the screeen does not react to any touch. What can be the problem?

    Thanks for the suggestion.
    We tried that. There was no change in the problem.
    This unit is right out of the box. I am currently charging it with a wall charger so it has a fresh charge. It is at 53% now but I am not sure how long this has been sitting.
    Thanks again.

  • Facebook does not react anymore since this Update?

    With Google Chrome and Safari facebook does not react anymore.
    Chrome gives server error
    Safari is blank.
    May be it has eo do with Facebook but it happened just after this update...?!

    Given the lack of discussions, it's likely that there's something isolated within your configuration or your network connection.  (This'd likely be producing mass panic, if it were a general problem.)
    I've intentionally blocked FB here via local means, so I'm not in a position to test the connection.
    Did you use any of the third-party Flashback removal tools?  If so, which one?
    Do you have any network-filtering, anti-malware or other security packages installed?
    Is your DNS setting aimed at your ISP DNS servers, or at the Google DNS 8.8.8.8 servers?

  • Windows message:program does not react

    I am using photoshop elements 11.Since a couple of weeks i frequently get the message:program does not react.

    Hi SigiEizo,
    More of us With same problems. I got elements 12 and it behaves same way.
    I cannot use it any longer, since I only get same answer as you: program does not react.
    Then it freezes and Locks.
    Anyone With a suggestion for what can be done.
    I have screened my pc for any malware and misperformance. Nor error reported.
    How do we get the program to work again??

  • When ipad connected to windows computer for sync I cannot install or remove an app. Screen does not react. Also lost my app store app from the ipad screen

    when ipad connected to windows computer for sync I cannot install or remove an app. Screen does not react. Also lost my app store app from the ipad screen. IPad is ipad 2 and op system is 8.1.1. Just tried full restore and still the situation is the same.

    For the missing App Store issue, if you swiped fro screen to screen to look in other folders and didn't find it, and did a spotlight search to see which folder it is in and had no success with that, Check Settings>General>Restrictions and make sure that you didn't disable it.
    You can also reset the home screen layout and the icon will reappear - but the home screen will return to the way that it looked when you first activated your iPad.
    Settings>General>Reset>Reset Home Screen Layout.
    For the syncing issue, which screen does not react, the computer and iTunes or the iPad?

  • HT4235 iPod nano 6th generation, syncing with audiobooks does not work now, had been working.  Sync test says:  No iPod touch, iPhone, or iPad found.  Connectivity test OK, no physical problems, iTunes shows the iPod.  Any clues what to do?

    iPod nano 6th generation, syncing with audiobooks does not work now, had been working.  Sync test says:  No iPod touch, iPhone, or iPad found.  Connectivity test OK, no physical problems, iTunes shows the iPod.  Any clues what to do?

    Hmm.. Thank you for the response.
    Have you tried using the iPod with another user account or computer, to help narrow down whether the problem lies with the computer, account, or the iPod itself?
    Maybe try reformatting it, using the tools provided by Windows. Instructions on how to reformat your iPod can be found in this article.
    http://www.methodshop.com/gadgets/ipodsupport/erase/index.shtml
    B-rock

  • Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. Thanks.

    Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. I am getting lots of spelling errors as the MacBook laptop screen is too small. Thank you so much! .

    Contentmom6 wrote:
    Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work.
    Normally, you just connect the monitor to the MacBook using a VGA adaptor that you can buy from an Apple Store.  Now try System Preferences > Displays > Detect Displays.  You should now be able to select a display mode for the monitor.  If it still doesn't work, then I'd check that everything is properly connected.  I've had problems with colours disappearing due to a faulty connection in the VGA adaptor.
    Bob

  • Notebook GX740 does not react to the power button

    Hello. Notebook GX740. When you upgrade NB Camera / VGA / EC Firmware laptop hangs. 1 hour turned it off the power. Now does not react to the power button. How can I restore NB Camera / VGA / EC Firmware??? The file downloaded from the website EC1727EMS1.404

    You will need to perform EC reset after EC flash.
    Remove battery and disconnect AC adapter, and then reconnect them.
    Try power on the unit.

Maybe you are looking for

  • MacBook Pro Bluetooth problems

    Anyone have any problems with BlueTooth mice and the MacBook Pro? I've got a 2010 17" MacBook Pro running 10.7.1 (but the problem pre-dates Lion). The mouse is "jerky" meaning that when I move the mouse it doesn't follow immediately sometimes, and im

  • Please read this on the Nokia Updater - Important ...

    Hi All, Well - it looks like you have really taken well to the new Nokia Software Updater. We can also see that there is a little bit of confusion about the service in its present state right now. So... We got an email from the NSU team that gives a

  • Switching broadband to another bt tariff during in...

    Hi everyone, I am in my 2nd month of an initial free 6 months  on BB option 1.I am finding that 10gb is not enough and would like to switch to the 40 gb tariff.Does anyone know if my "discount" of £13 per month for the remaining 4 months would also b

  • Installation 10g and Apex on different server

    Hallo, I trying to install Oracle 10g Standard Edition on one server and the Oracle HTTP Server with HtmlDB/Apex on another one. Both systems are Linux (Ubuntu 8.4). The database works fine and the the Installation of HtmlDB with HTTP Server from the

  • Actually in my project The middle tier was written using RMI.The Database i

    Actually in my project The middle tier was written using RMI.The Database interaction was defined in the middle tier itself.My problem is , the queries we post to the database should interact with XML Database which in turn should interact with the a