Turning an icon into a button in a table

Currently, I access a database in my program, and if I find an 'X' in a specific column, I place an icon in that field. What I would like to do is have that icon act as a button, that will pop up a screen with further information about the table line item. I am new at Java, and not sure what to do next.
Here is the code for my table model:
class sciTableModel extends javax.swing.table.DefaultTableModel
     public sciTableModel()
          super();
     public sciTableModel(java.util.Vector data, java.util.Vector columnNames)
          super(data, columnNames);
and here is the code for my renderer
class IconRenderer extends DefaultTableCellRenderer
     public Component getTableCellRendererComponent(JTable table,
     Object value, boolean isSelected, boolean hasFocus, int row, int column)
          ImageIcon iconl = new ImageIcon("info.gif");
          String headerText = (String)value;
          // System.out.println(headerText);
          JLabel headerComponent =
          ((JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column));
          headerComponent.setHorizontalAlignment(SwingConstants.CENTER);
          if (headerText != null)
               headerComponent.setIcon(iconl);
               headerComponent.setText("");
          else
               headerComponent.setIcon(null);
               headerComponent.setText(null);
          return headerComponent;
In the public class I set the renderer, and in the actionevent that runs the database access I use the tablemodel.
Any help on how I can turn this icon into a button would be appreciated.

In A JTable, the render has the job of drawing one or more cells, but it's a rubber stamp -- it doesn't
respond to events like a true component. What you describe isn't the job of an cell editor either,
since, obviously, nothing is being edited. That leaves JTable itself: I suggest you write a mouse
listener for your JTable and respond appropriately when the right cell is clicked:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test {
    public static void main(String[] args) {
        JTable table = new JTable(20, 5);
        table.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent evt) {
                JTable t = (JTable) evt.getSource();
                Point point = evt.getPoint();
                int col = t.columnAtPoint(point);
                int row = t.rowAtPoint(point);
                if (col != -1 && row != -1) {
                    int modelCol = t.convertColumnIndexToModel(col);
                    System.out.println("clicked on model cell (" + row + "," + modelCol + ")");
        JFrame f = new JFrame("Test");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JScrollPane(table));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
}As the code demonstrates, don't forget to translate from view columns to model columns.
By the way, why are you subclassing the default table model? You aren't changing any behavior...

Similar Messages

  • Making a loaded external image into a button in Actionscript

    My name is Steve Oatman I am a student at
    AIO for a Web Design Diploma
    class: Interactive Telecommunications IMD412 XA
    Professors to bussy!
    I have a flash web site that I am putting together. I am using AS to load some images from an external source. These images are being loaded into a movieclip. These images need to become buttons once they are loaded. The images will link to the particular menu category pages beef, chicken, etc.
    The images are loading fine they just are not responding like a button or link.
    I am getting two error referencing the buttonMode and usehandCursor. Below is just one image that I am working on till I get it to work.
    I am getting these two Compiler error code:
    1119: Access of possibly undefined property buttonMode through a reference with static type flash.display:Loader.
    1119: Access of possibly undefined property useHandCursor through a reference with static type flash.display:Loader.
    This is what I have.
    var myLoader01:Loader = new Loader();
    myLoader01.load(new URLRequest("entrees_images/beef/beef01.gif"));
    addChild(myLoader01);
    myLoader01.x = -269;
    myLoader01.y = -164;
    myLoader01.buttonMode = true;
    myLoader01.useHandCursor = true;
    myLoader01.addEventListener(MouseEvent.CLICK, beefClick);
    function beefClick(event:MouseEvent):void{
    gotoAndStop("beef");
    From me searching online I thought the
    name.buttonMode = true;
    turned the element into a button!
    I have included the fla file. This is in the menuItems_mc which is located in the pageContent_mc frame 40 layer page Image or of course the library.
    I know this is a little in depth sorry and any help would be greatly appreciated.
    Steve
    713/742-3325

    Try something along the following lines:
    var myLoader01:Loader = new Loader();
    function addIt(evt:Event):void{
       var aBtn:MovieClip = new MovieClip();
       aBtn.x = -269;
       aBtn.y = -164;
       aBtn.buttonMode = true;
       addChild(aBtn);
       aBtn.addChild(myLoader01);
       aBtn.addEventListener(MouseEvent.CLICK, beefClick);
    myLoader01.contentLoaderInfo.addEventListener(Event.COMPLETE, addIt);
    myLoader01.load(new URLRequest("entrees_images/beef/beef01.gif"));
    function beefClick(event:MouseEvent):void{
       gotoAndStop("beef");

  • When I download Adobe Reader XI, it turns all my icons into Adobe Reader.  How do I prevent it?

    When I download Adobe Reader XI, it turns all my icons into Adobe Reader.  How do I prevent it from changing everything?

    You may find this useful:
    http://helpx.adobe.com/acrobat/kb/application-file-icons-change-acroba t.html

  • How do I turn a Smart Shape into a Button?

    Using Version 7, on a Content Master Slide how do I turn a Smart Shape into a Button?

    Hi there
    It's really hard. You have to look at the properties of the Smart Shape.
    Cheers... Rick

  • Why does Adobe Reader download turn all my icons into Adobe Icons?

    I am using Windows 7 and trying to install Adobe Reader 10. I have tried it numerous ways, but it continues to turn all my icons into Adobe Icons. Why?

    Please have a look at: http://kb2.adobe.com/cps/860/cpsid_86069.html to rectify the issue wherein all files get associated with Adobe Reader.

  • After my computer has been asleep and I touch my trackpad, it wakes enough to show my icon but not enough to acknowledge my keyboard or trackpad so I can type a password.  It seems the only way to make it work it to turn it off the back button.

    After my computer has been asleep and I touch my trackpad, it wakes enough to show my icon but not enough to acknowledge my keyboard or trackpad so I can type a password.  It seems the only way to make it work it to turn it off the back button.

    The reason, I included the annotation that I'd upgraded my Itunes, (On my Computer) is B/C in many forums - the very first question, *HELPERS* ask, is. "Do you have the latest version of Itunes downloaded on your computer." I wanted to knock out any obvious replies.
    Now-  "DO YOU have any idea,"... how your UNHELPFUL remarks, do absolutely nothing but hurt others that might not have the EXPERIENCE you have? How do you expect people to know things without asking questions? Whew! RUDE!!
    Message was edited by: Apple I0S Help Team

  • My update buttons all turn into open buttons

    I had this happen on my iPad and it took a software update to fix.
    I open the app store (currently with a badge of 24 apps). I go to updates. All of the apps that need updated have an update button next to them, however, those buttons turn into "open" buttons in about half a second. Tapping them simply opens the apps.
    I've updated to the latest software and still no luck, it's misbehaving. This is not cool. Any help appreciated.
    Dan P.

    Hi Dan,
    If you are having issues with your App Store update buttons changing to Open buttons, you may want to try some things to troubleshoot.
    First, quit all running applications and test again -
    Force an app to close in iOS
    Next, I would try restarting and if needed resetting the iPhone -
    Restart or reset your iPhone, iPad, or iPod touch
    If the issue is still present, you may want to restore the iPhone as a new device -
    How to erase your iOS device and then set it up as a new device or restore it from backups
    Thanks for using Apple Support Communities.
    Best,
    Brett L  

  • Turn off icon preview on all folders?

    Looking for a good way to turn off icon previews on all folders, especially on a networked drive. 
    If I open a folder and choose View > Show View Options, I can turn off the icon previews for that folder, but the others remain unchanged. (Even if I push the use as defaults button)
    Is there a script to command that I can run to change this on all folders recursively?

    Thanks!!! I had been looking for like 25mins before i luckily ran into this thread!

  • I was asked to update my Foxfire which I did but at one point it said I would be prompted to move the Foxfire icon into the applications folder and I was never prompted to do so, therefore I do not know what to do next.

    The new Foxfire version was downloaded into my download folder but I was never prompted, as it said I would be , so move the Foxfire icon into the applications folder. Therefore I do not know where the process stands. It old icon in my dock upgraded or has nothing happeded. It seems as if the process somehow just stopped in the middle.

    Outside of the contact number for that you've already used I don't know another way of direct contact. Here are some things that they may or may not of had you try that might help you. If you will go to the settings app and pick general on the right-hand side you will see accessibility. Within that you can adjust a text size make the text bowl you can also increase the contrast. You can also adjust the brightness and control panel.
    As for Siri again in the settings app under general you should see Siri on the right-hand side with the switch to turn it on. If that is turned on and you're still having issues
    Try a Restart. 
    Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider. Press and hold the Sleep/Wake button until the Apple logo appears.
     Resetting your settings
    You can also try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your device settings again.... All of the settings in the settings app will have to be re-entered. You won't lose any data, but it takes time to enter all of the settings again.
    Resetting your device
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears. Apple recommends this only if you are unable to restart it.
    Or if this doesn't work and nobody else on the blog doesn't have a better idea you can contact Apple. 
    Here is a link to their contacts with most of the information below. 
    http://www.apple.com/contact/

  • My ipod touch 5th generation will not turn on and the home button doesn't work. what do i do?

    Hello my name is Leslie and i would like to ask you guys a question on how to fix my ipod or what is wrong with it. My ipod touch 5th generation will not turn on and the home button doesn't work. what can i do to fix it ?

    Has the home button worked in the past, or is this been something that hasn't worked for some time? The only way to reset the device is with the sleep/wake (power) and home buttons together. Without it, you would have to wait until the battery dies and then plug it in to try and reset it. The Home button is used for several user troubleshooting steps. Without it, you cannot perform a reset, put the device into recovery mode, or place it in DFU mode. You need to get the home button repaired.

  • Trouble displaying icon on push button in 6i Forms

    Hi,
    I'm having trouble displaying an icon on a button at both design and run times. I'm using Forms 6i with client/server enviornment. I have tried to follow several forums regarding icon setup and the Whitepaper articles. I have tried different suggestions but am still unable to get the icon. Here's my latest attempt:
    1. Copied .jar file to C:\Oracle_Developer_9i\forms90\java folder
    2. Modified formsweb.cfg (in the serverApp=default section) and included the following:
    archive_jini=f90all_jinit.jar,myAppIcons.jar
    imagebase=codebase
    3. In button's properties I set:
    iconic = 'Yes'
    icon filename = C:\Oracle_Developer_9i\forms90\java\myAppIcons.jar
    My guess is that I didn't copy the icon files (from the .jar file) correctly. As suggested in the Whitepaper, I don't have the c:\ myApp\ icons directory. I did a search for an icon directory and found multiple icons folders (due to other oracle projects installed on my pc) but don't know which one to use. Being that I'm using 6i and the instructions were for 9i I didn't know if the directory/folder name is different. Is there another directory/folder (using 6i) where I should copy all the .gif files from in addition to storing the .jar file in the C:\Oracle_Developer_9i\forms90\java directory?
    Also, I feel that I'm not calling it correctly from the location in step 3. Being that the icon exists in the jar file, how would I reference it within the file? Does anybody have any suggestions? Any help would be greatly appreciated.
    Thank you,
    Eric

    Robin,
    I tried your suggestions but am still unable to view the icon. Here's what I now have tried.
    1. I've created UI_ICONS in the windows registry under the form's oracle home and am calling c:\icons from that variable.
    2. In c:\icons, I copied the .jar file's contents (search.gif) into this folder. This is where I may have a problem in addition to my next step in calling the filename. You mentioned in your first post to put my .ICO files there. Should I rename my .gif to .ico? Not sure if I followed you there.
    3. In the button property, I set icon = yes and icon filename = c:\icons\search.gif -- Not sure if I used the right syntax for the filename. I've tried renaming it to .ico and it still does not display.
    Sorry about all the questions but I really appreciate your help. Do you see anything else that I did that may cause it to not display?
    Thanks again,
    Eric

  • IDCS3 How to convert checkbox into form button in PDF?

    I have an InDesign CS3 document that has lots of text checkboxes next to items in a list.
    I would like to be able to export this doc as PDF and have those checkboxes turned into form buttons that the reader can toggle on or off to indicate items that the reader owns.
    Then the reader could print the PDF and they would have a nice neat record of their items.
    At present I don't need to have these PDF forms returned electronically or tallied or anything. The idea is just to use the PDF as a personal inventory.
    So I'm hoping there's some easy way to globally replace my text-based checkboxes in IDCS3 with buttons that look the same but which will be recognized properly by Acrobat as interactive objects the state of which can be toggled with a click.
    I've tried reading all the help files and searching these forums, but can't figure out how to do this. Any suggestions would be greatly appreciated. Thanks in advance!

    You cannot do this in InDesign.
    However, you can export a PDF file and open it in Acrobat 8 Professional or Acrobat 9 Pro. Then you can use the Form Field Recognition feature (Forms menu) in Acrobat 8 or Start Form Wizard in Acrobat 9 Pro.
    Head to the Acrobat User Community tutorials and eSeminars for more information:
    http://www.acrobatusers.com

  • Turn a script into an .exe file?

    Hi,
    How can I turn a JavaScript into an .exe file (on Windows)? The
    advantage is that if the script uses only ScriptUI features, it will
    never need to launch InDesign. Additionally, it is possible to package
    it that way with a special icon that appears if it is placed on the
    desktop, and when it runs the icon appears in the taskbar.
    An example of what I'd look to achieve is the hyphenchecker script,
    written by the late Teus de Jong. There is one Windows-only version
    available on his website (which is still being maintained, probably by
    his son) which is an .exe file -- precisely what I'm trying to do.
    Thanks,
    Ariel

    straight form javascript i don't think there is a way.
    however you can use, i think, Visual Basic (not vbScript!!) as a wrapper for js (using doScript)?

  • New to bb. Can I move icons into one folder?

    Hi, to the forum. I'm new to BB and I will appreciate some help.
    1.- I have a few games, but I will like to have all of them on one folder. e.g. chess, blackjack, etc, under games. Is there a way to do this. I created a new folder (Games) but I do not know how to move the icons into it. I tried to drag them, but does not work.  
    2.- In the near future I will travel to southamerica and I do not know if I can use my BB with a local sim card. I  owned an unlocked Palm Treo that let me buy a local sim card and used it to communicate in the country I was visiting. Will I be able to do the same with my BB??
    Any ideas or answer.
    thanks
    BB Curve with Tmobile

    Welcme to the Frums!
    I can help you with your first question. 
    you can go to your main screen and press the Menu button > The ADD FOLDER >  name it what you want to name it. Then you can click and move  the icons into the folder.
    Nurse-Berry
    Follow NurseBerry08 on Twitter

  • Have just turned my beloved into a PC by downloading Mavericks.  How do I get rid of it?

    Have just turned my Apple into a PC by downloading Mavericks.  How do I get rid oif it?

    Erase the hard drive, then restore your old system from your backup. Otherwise,
    Install Mavericks, Lion/Mountain Lion Using Internet Recovery
    Be sure you backup your files to an external drive or second internal drive because the following procedure will remove everything from the hard drive.
    Boot to the Internet Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND-OPTION- R keys until a globe appears on the screen. Wait patiently - 15-20 minutes - until the Recovery main menu appears.
    Partition and Format the hard drive:
    1. Select Disk Utility from the main menu and click on the Continue button.
    2. After DU loads select your newly installed hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Click on the Options button, set the partition scheme to GUID then click on the OK button. Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the process has completed. Quit DU and return to the main menu.
    Reinstall Lion/Mountain Lion. Mavericks: Select Reinstall Lion/Mountain Lion, Mavericks and click on the Install button. Be sure to select the correct drive to use if you have more than one.
    Note: You will need an active Internet connection. I suggest using Ethernet
                if possible because it is three times faster than wireless.
    This should restore the version of OS X originally pre-installed on the computer.
    If you originally started with Snow Leopard:
    Clean Install of Snow Leopard
    Be sure to make a backup first because the following procedure will erase
    the drive and everything on it.
         1. Boot the computer using the Snow Leopard Installer Disc or the Disc 1 that came
             with your computer.  Insert the disc into the optical drive and restart the computer.
             After the chime press and hold down the  "C" key.  Release the key when you see
             a small spinning gear appear below the dark gray Apple logo.
         2. After the installer loads select your language and click on the Continue
             button. When the menu bar appears select Disk Utility from the Utilities menu.
             After DU loads select the hard drive entry from the left side list (mfgr.'s ID and drive
             size.)  Click on the Partition tab in the DU main window.  Set the number of
             partitions to one (1) from the Partitions drop down menu, click on Options button
             and select GUID, click on OK, then set the format type to MacOS Extended
             (Journaled, if supported), then click on the Apply button.
         3. When the formatting has completed quit DU and return to the installer.  Proceed
             with the OS X installation and follow the directions included with the installer.
         4. When the installation has completed your computer will Restart into the Setup
             Assistant. Be sure you configure your initial admin account with the exact same
             username and password that you used on your old drive. After you finish Setup
             Assistant will complete the installation after which you will be running a fresh
             install of OS X.  You can now begin the update process by opening Software
             Update and installing all recommended updates to bring your installation current.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.

Maybe you are looking for

  • XML Schema for Java Bugs

    I've just downloaded your XML Schema for Java software are have been systematically testing it with a relatively simple document. A few bugs: 1. the use="required" attribute of the attribute element doesn't have any effect (doesn't show any error mes

  • ITunes won't recognize my iPod 5

    I just got an iPod 5. I started it and plugged it into iTunes on my Mac, but niether the iPod nor iTunes is showing a connection. I've tried updating and restarting EVERYTHING, I've done all of the troubleshooting related to the topic, but nothing. W

  • Refurbishment with no serialisation of materials

    Hi Friends , I have one doubt regarding refurbishment process . As far as I know we can implement it in two ways : 1) with serialization of material 2) without serialization also . Without Serialization we can follow these steps : 1) Create and order

  • Bubble chart drill down

    HI All, We have 4 levels like(Continent,Country,State,Dist). Our business Req is like drill down from entity at  one level to another entity at the following level.Each Entity has one to many relation ships with entities in the subsequent levels. For

  • MacBook Pro only had local internet...

    Hi anyone... This is a really bizarre one: I am currently at my Windows PC, because my MBP for some reason can only connect to local internet sites (I'm in South Africa, so it only connects to South African servers). The Windows PC I am using is conn