Results 1 to 3 of 3
  1. #1
    SteM is offline Member
    Join Date
    Nov 2007
    Posts
    6
    Rep Power
    0

    Default Color of the focued row in a JTable

    Hi all,
    i'm configuring a JTable to have a controlled set of colours.
    I'm able to control all the aspect but the color of the row with the focus.
    Example: the row that receive the focus via mouse click ....
    I always have a dark blue as color, i need a light blue !!

    I'm also testing a TableCellRenderer, but again i'm not able to control that color !! :confused:

    Thanks,
    regards

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    I'm also testing a TableCellRenderer, but again i'm not able to control that color
    The logic can be a little tricky to get right. Look in the DefaultTableCellRenderer class source code - in the src folder in your sdk distribution. You can get an idea of how to implement the focus part in your cellRenderer.
    Added:
    The other alternative is to set the UI default color which will affect all JTabels in your app. Make sure you set this before creating any tables.
    Java Code:
    import javax.swing.plaf.ColorUIResource;
    ...
    Color lightBlue = yourColor...
    ColorUIResource colorResource = new ColorUIResource(lightBlue);
    UIManager.put("Table.focusCellBackground", colorResource);
    Last edited by hardwired; 11-20-2007 at 06:38 PM. Reason: added suggestion

  3. #3
    SteM is offline Member
    Join Date
    Nov 2007
    Posts
    6
    Rep Power
    0

    Default

    Solved !! :D

    In the paint() function i get the background color that is yet modified by the basic mechanism!!
    I solved passing the background colours on the renderer constructor and used them instead of the returned by JTable.getBackground() or getSelectedBackground() functions ....

    :p
    Last edited by SteM; 11-21-2007 at 09:52 AM.

Similar Threads

  1. Replies: 6
    Last Post: 05-14-2011, 06:48 AM
  2. Change the color in my program
    By carl in forum New To Java
    Replies: 5
    Last Post: 04-03-2009, 12:20 PM
  3. Help with switch color
    By Daniel in forum AWT / Swing
    Replies: 2
    Last Post: 09-18-2008, 07:54 AM
  4. Color objects
    By CyberFrog in forum New To Java
    Replies: 4
    Last Post: 04-01-2008, 12:41 AM
  5. A bit of color!
    By tim in forum Java 2D
    Replies: 8
    Last Post: 02-11-2008, 11:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •