Trying to change the color of a single cell

hi, I am trying to change the color of a single cell when mouse moves over it, but couldn't do it. i even tried my own renderer, but it doesn't work. can anybody help ?

Here is what I am trying to do. I am displaying some data in a java JTable retrieved from a table in database. What is needed is when user moves his mouse over any cell in the third column, the cursor should change to hand cursor and possibly the background color should also change, to indicate the user that this cell is clickable. I have to show some other report when user clicks any cell in column three. The code follows as
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
import javax.sql.rowset.*;
import javax.swing.table.*;
public class MouseMotionInTable extends JFrame
public static void main(String[] args)
  MouseMotionInTable f = new MouseMotionInTable();
  Toolkit tk = Toolkit.getDefaultToolkit();
  Dimension dim = tk.getScreenSize();
  int w = dim.width;
  int h = dim.height;
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setBounds((w-600)/2, (h-300)/2, 600, 300);
  f.setVisible(true);
MouseMotionInTable()
  Connection con = null;
  CachedRowSet crs = null;
  try
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   con = DriverManager.getConnection("jdbc:odbc:FMS", "", "");
   Statement st = con.createStatement();
   String query = "SELECT ItemName, Alias, ItemReOrderQuty, ItemMeasure FROM ItemInfo";
   ResultSet rs = st.executeQuery(query);
   crs = new com.sun.rowset.CachedRowSetImpl();
   crs.populate(rs);
   st.close();
  catch (SQLException e)
   e.printStackTrace();
  catch (ClassNotFoundException e)
   e.printStackTrace();
  finally
   if(con != null)
    try
     con.close();
    catch (SQLException e)
     e.printStackTrace();
  DBTableModel model = new DBTableModel(crs);
  table = new JTable(model);
  JPanel center = new JPanel();
  center.setLayout(new BorderLayout());
  center.add(new JScrollPane(table), BorderLayout.CENTER);
  add(center, BorderLayout.CENTER);
  table.addMouseMotionListener(new MouseMotionAdapter()
   public void mouseMoved(MouseEvent me)
    int col = table.columnAtPoint(new Point(me.getX(), me.getY()));
    int row = table.rowAtPoint(new Point(me.getX(), me.getY()));
    if(col == 2)
     Object val = table.getValueAt(row, col);
     boolean isSelect = table.isCellSelected(row, col);
     boolean focus = table.isCellSelected(row, col);
     TableCellRenderer cellRender = table.getCellRenderer(row, col);
     Component comp = cellRender.getTableCellRendererComponent(table, val, isSelect, focus, row, col);
     comp.setCursor(new Cursor(Cursor.HAND_CURSOR));
     comp.setBackground(Color.yellow);
private JTable table;
class DBTableModel extends AbstractTableModel
ResultSet rs;
ResultSetMetaData rsMeta;
DBTableModel(ResultSet rs)
  try
   this.rs = rs;
   rsMeta = rs.getMetaData();
  catch(SQLException e)
   e.printStackTrace();
public int getColumnCount()
  try
   return rsMeta.getColumnCount();  
  catch(SQLException e)
   e.printStackTrace();
  return -1;
public String getColumnName(int c)
  try
   return rsMeta.getColumnName(c+1);
  catch(SQLException e)
   e.printStackTrace();
  return "";
public int getRowCount()
  try
   rs.last();
   return rs.getRow();
  catch(SQLException e)
   e.printStackTrace();
  return -1;
public Object getValueAt(int r, int c)
  try
   rs.absolute(r+1);
   return rs.getObject(c+1);
  catch(SQLException e)
   e.printStackTrace();
  return "";
public boolean isCellEditable(int r, int c)
  return false;
public Class getColumnClass(int c)
  return getValueAt(0,c).getClass();
}

Similar Messages

  • Hello. I am trying to change the colors on my ical. I have been able to select a calendar group, click "get info" and then "other" in the color options and which point a a lot of color options are available. HOWEVER, I can't seem to select the color.

    Hello. I am trying to change the colors on my ical. I have been able to select a calendar group, click "get info" and then "other" in the color options and which point a a lot of color options are available. HOWEVER, I can't seem to select the color. I click on a new color and press enter and nothing happens...not sure what I am doing wrong.

    What do you currently see?
    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    Use a compressed image type like PNG or JPG to save the screenshot.
    Do you have the menu bar?
    *Press the F10 key or tap the Alt key to bring up the hidden Menu bar.
    Do you have any toolbars visible at all?
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Make sure that you do not run Firefox in full screen mode (press F11 or Fn + F11 to toggle; Mac: Command+Shift+F).
    *https://support.mozilla.org/kb/how-to-use-full-screen
    You can check for problems caused by a corrupted localstore.rdf file.
    *http://kb.mozillazine.org/Corrupt_localstore.rdf

  • I am trying to change the color of a background layer and it will not accept the color I want

    I am trying to change the color of a background layer and it will not accept the color I want

    If you want to get help you may have to provide a lot more details about what you are doing (which tools or commands do you use, what exactly happens when it fails, …)?

  • How do I change the background of a single cell or a row in a table?

    How do I change the background of a single cell or a row in a
    table? I doesn't seem to be letting me do that.

    Are you using the latest DW? If so, then it isn't letting you
    because
    bgcolor is deprecated and shouldn't be used.
    The correct way is to use css to define the background of a
    cell
    CSS:
    .blackcell {background-color: black;}
    HTML:
    <td class="blackcell">whatever in the cell</td>
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Template Customization ~
    http://www.csstemplates.com.au
    Spry Widget Examples
    http://www.dreamweaverresources.com/spry-widgets/
    "dm25" <[email protected]> wrote in message
    news:f4jr5h$luu$[email protected]..
    > for some reason that doesn't always work. When I click
    inside a cell, it
    > doesn't give me an option to change the background
    color.

  • Changing the color of a single field in a row of a table

    Is it possible to change the color of text of a single field within a single column. If field 'C' in a row is negative number change the text color to red. Is this possible?

    Hi Champion,
    Please Do search before posting.. you get lots of threads here...
    Re: color for a particular column in table
    Re: Color a table row
    Please go through this..
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/707fb792-c181-2d10-61bd-ce15d58b5cf1?QuickLink=index&overridelayout=true

  • Trying to change the color of the title?

    Through the Titles feature, I've created a title. It has come out white. Now I want to change the color.
    I went to Help and it says to "Select the title in the Project Browser, and then click Show Fonts in the viewer. The iMovie Font Panel opens."
    I selected the title, but then I could not find anything that says "Show Fonts." Can someone help? Thanks.

    James Snedeker wrote:
    .. how do I create my own titles with which I can change the colors/fonts/etc?
    if you don't need the title over video, use any 'paint'.app to create your own title design (btw: Keynote offers nice templates...), import 'chart' as a still.
    if you need the title over video, follow advice and get some inspiration on my site:
    http://sites.google.com/site/karstenschluter/imovie09tricks
    btw: if the DevTools are installed on your Mac, and you're familiar with the tool QuartzComposer, you can change font and color in all 'effected' titles.. but tricky

  • Error trying to change the value property of a cell with decimals

    This is a script question.
    I’m using a system defaulting to Spanish, so the decimal delimiter is the comma.
    During a script I need to change the property value of a cell multiplying it by -1. As an example, I want to change 1,25 into -1,25.
    This is how try to do it:
    tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
    set selection range to first cell
    set mi_cell to (value of first cell of selection range) * -1
    set value of first cell of selection range to mi_cell
    end tell
    The expected result is wrong provided that the original value of the cell has decimal value. Otherwise is correct.
    See examples of what happen after running this piece of the script:
    1,25 becomes -125,00 instead of -1,25
    6,00 becomes -6,00 (in this case is correct)
    Does anybody know how to solve this problem?
    Thanks in advance.
    Ratz

    This was described here in several scripts.
    Before setting the value of a cell to a number or a date, the value must be coerced to a string.
    It's the only way available to take care of localization features.
    Your script must be
    tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
    set selection range to first cell
    set mi_cell to (value of first cell of selection range) * -1
    set value of first cell of selection range to mi_cell as text
    end tell
    or better
    tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
    set mi_cell to (value of first cell) * -1
    set value of first cell to mi_cell as text
    end tell
    CAUTION : don't code
    tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
    set mi_cell to -(value of first cell)
    set value of first cell to mi_cell as text
    end tell
    which is supposed to do the same but would return the opposite of *_the integer value_* of the cell.
    Yvan KOENIG (VALLAURIS, France) dimanche 13 février 2011 16:06:39

  • How can I change the color of a single object?

    I have a bright orange barrel in a video of mine and I want to change it to a cooler color without changing the rest of the scene? How can I do this?

    Hi
    In FCP, under the help menu, choose Final Cut Pro Help.
    When it opens, search for " Using the Limit Effect Controls of the Color Corrector Filter to Change a Specific Color".
    MtD

  • I am trying to change the color background in the Sports Theme of Imovie 11

    I am using the Pre-Set Theme (Sports) and want to change the theme color from blue to green.  Any ideas of how to do this?

    No unfortunately those themes are baked right into iMovie and not to be altered unfortunately. In a manner of speaking, What you see is ALL that you get. Everybody gets the same color no matter what.

  • Change the color of the outer line of a shape

    Hello I'm trying to create a rectangle with a red border and no inside fill. It's only to highlight some text of a bank form.
    I know i have to right click the layer and choose blending options and stroke. But I've tried to change the color so many times and no matter what I do, the outer line remains gray and with rounded corners.
    I want the corners of the rectangle to be squared, not rounded but I'm having a hard time changing this.
    Please help
    I'm using Photoshop CS3
    thank you
    Could anyone please show a picture of where to change the color of the outer line? I've tried everything.

    Hi,
    With Ps CS3, you'll probably want to define a Layer Style for a Stroke and then use that with the Square Shape Layers.
    This is a Stroke of 4 px, 'Centered' (so a very slight corner rounding on the outside edge. 'Inside' will give you square corners for both inside and outside edges). To change the color of the stroke, go to Layer> Layer Style> Stroke and change the color by clicking on the color bar.
    regards,
    steve 

  • Changing the color of a registered trademark symbol in a logo and what is the the symbol's size?

    I have a logo with the registered trademark symbol.  I tried to change the color of the registered trademark symbol to the same color as the logo, using the color replacement tool but it did not work.  Is there another way to change its color?
    Also, I need to find out how big the registered trademark symbol is in comparison to the logo.  (height, width, how far away from the logo the symbol is).  How do I do this?  Trying to use the Ruler tool was a disaster.  As you've probably noticed, I'm very new to Photoshop.
    thanks,

    Depending on what colors you are working with adding a layer above the logo with the "color" layer style may work for you. This really only works if the logo is on white and the TM isn't black or white.
    For Example:
    Before
    Paint (on a new layer) the new color
    Change the layer style of that new green layer to "color"
    And voila!
    If you're working with a black or white TM you may just have to mask it out and make a new one with the text tool, I'm not aware of another way to change it (though I'm not the photoshop guru some of these people are =D)

  • Is it possible to change the color of the folders in Mail

    I just tried to change the color of the IMAP folders in Mail.
    I want to mark some of the folders to find them easier.
    so it would help if i can chance the color of the Name or Icon.
    Thanx

    Sorry, but i found some old discussions like this...
    please delete

  • How do I change the color of the users name after they sign in?

    I am trying to change the color of the users name after they have signed in on the top right hand corner. When you hove over the login it shows up "Welcome (Users name) Log Out", The "welcome" and "log out" are in white and I know how to change them, but trying to find out how to change the name so it appears a different color is getting the better of me. Please help.

    Hi blackroseuk7,
    You can use firebug to inspect the element to see what div to target and from there you can set the color with CSS.
    Hope this helps!
    Carol - BCGurus.com

  • Gantt chart- How to change the color of time bars of different versions

    Hi All,
    My Client wants to see all changes in planning schedule. I made different versions of these changes but he also want to see all these changes in gantt chart and in different colors. I tried to change the color in planning board assistant but in this screen (CJ27/ CJ2B). we cannot view all versions together. And if I use CN41, there I cannot change the colors of time bars.
    Secondly, we can change colors of times bars of basic dates, forecast dates and actual dates but there is no provision to change the colors of schedule bars of different project versions. Kindly reply-
    1. How to see all project versions in CJ27 or How to customise bar chart in cn41 or if we change in SPRO, then how to change graphic profile in project info profile
    2. How to change colors of different time bars of different versions.
    3. How to mention these legends (meaning of each color in chart) at footer of gantt chart (in print outs)
    Please Help.
    Thanks & Regards
    Dinesh Chauhan

    Thanks,
    actually I've created new project planning board profile where planning board assistant is customized but unable to use this profile in CN41. we can change PS info profile in CN41 and that;s why I thought that planning board profile may be assigned somewhere in PS info profile so that changes in planning board assistant will be applied in CN41 through PS info profile. Graphic profile is too complex to understand and not sure if it will help to get colored time bars of projct versions in gantt chart. Still not clear.
    Secondly not able to see all versions (snap shots) in gantt chart with different colors of time bars.
    I mean planning board screen can be customized but we cannt see different versions here which are possible in CN41, but we cannt customize the gantt chart (time bars) in CN41. Pls help.
    Thx & Regards
    Dinesh Chauhan

  • How can i change the color of NELevelIndicator

    I am trying to change the color of the stars in the NSLevelIndicator.  I would like inactive stars to be red outlines and active stars to be yellow solid stars.

    OMG,So do I hate the new iTunes,its horrible & Ive had real bad synching problems,so i really hate it & im looking for a way to make it like the previous ,i liked that interface,this 10 is plain & boring

Maybe you are looking for

  • IDOC- BPM- File - Acknowledgements

    The Scenario is to send IDocs from SAP through BPM to a file system. I want an acknowledgement to be sent back to SAP system incase of any error while writing the file. To simulate an error, I am giving an unauthorized file path. I have enabled appli

  • IMovie 11 Freezing at startup and file structure

    Hi, I know others have asked about iMovie 11 freezing at startup. I haven't, however, seen much discussion of the event file structure. To solve the freezing startup, I put all the event directories (folders)  in a temp folder and brought only the ne

  • Can't create connection with Data Modeler 2.0.0 570

    I have installed SQL Developer Data Modeler on my Windows Vista Home Premium system and am unable to create a connection to import a Data Dictionary. When I select TNS from the connection type dropdown list , I get a message below that states: 'Warni

  • DocClose event runs twice after extending with user rights

    I have created a form with several fields. To check if the fields are filled, I have placed several checks if the DocClose event. This creates a messagebox containing text of the missing fields. This will only popup when the pdf is closed. See below

  • Images in the folders of an external file system KM

    Hello, We are facing a problem in our KM, the thing is We have created a external file system in our KM, it is green and almost everythings is working fine... In the CM repository we have assigned the "properties" as a repository services, but in the