Help needed badly with coloring of specific cells in a tble

I have an existing table and when this code, it colors all the cells in a column. Hoe can I use the funktion getCellRenderer: to color only one cell at a time and implement it in an already existing table.
THX for any help I can get :)
ColorRenderer cell=new ColorRender();
// for(int i=0;i<table.getModel().getColumnCount();i++){
// TableColumn mod=this.getColumn((this.getModel().getColumnName(i)));
mod.setCellRenderer(cell);
And ur ColorRender calss should override DefaultTableCellRenderer like this
class ColorRenderer extends DefaultTableCellRenderer {
protected int align;
public ColorRenderer(int align) {
this.align=align;
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
setHorizontalAlignment(align);
super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
if(col==4){
setBackground(Color.cyan);
return this;
}

Here's a bit of Friday Fun: before you run this code, what do you think the table will look like?
What will it look like as you click and drag on it to select cells?
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class X {
    static class R extends DefaultTableCellRenderer {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component that = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            Color bk = that.getBackground();
            that.setBackground((row + column)%2==0? bk.darker() : bk.brighter());
            return that;
    public static void main(String[] args) {
        JTable table = new JTable(20,10);
        table.setDefaultRenderer(Object.class, new R());
        JFrame f = new JFrame("X");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JScrollPane(table));
        f.setSize(400, 300);
        f.setLocationRelativeTo(null);
        f.setVisible(true);

Similar Messages

  • Set color of specific cells in JTable.

    I have a JTable where I want to set the color for specific cells. Is this possible to do, and if so, how?

    Well, one way is to create a custom renderer that know the background color of each cell in the table. The Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer]How to Use Table has an example you might be able to build on.
    Or, this posting may give you another approach. The key to both solutions is to somehow specify the color for every cell:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • Help needed please, with Iphone stuck with apple picture and progress bar after software update attempted

    Help needed please, everytime I try to update the software version on my iphone it comes up with a message saying it could not be completed and is now frozen with the apple picture and progress bar on it. Do I unplug it and hope the macbook pro sees it again, I also stupidly did not back up before starting the download which I realise I will have to go back to the previous back up. This keeps happening, everytime I do this type of update, I'm starting to think I should just give up on updating my software on the Iphone. I thought it was happening because I was using a window based computer to do the updates, this time I used my Macbook Pro. Please somebody help

    ljm17 wrote:
    ...This keeps happening, everytime I do this type of update, I...
    Then you should know what you need to do... If you don't remember...
    See Here  >  http://support.apple.com/kb/HT1808

  • How to color a specific cell in ALV (not REUSE_ALV_GRID_DISPLAY)

    Hi
    I want to change color font or background to a specify position in ALV grid
    It is possible but by creating ALV container (not FM for example REUSE_ALV_GRID_DISPLAY)?

    Hi,
    REPORT ZALV_LIST1.
    TABLES:
    SPFLI.
    TYPE-POOLS:
    SLIS.
    PARAMETERS:
    P_COL TYPE I ,
    P_ROW TYPE I,
    P_COLOR(4) TYPE C .
    DATA:
    T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
    FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
    W_COLOR(4) ,
    W_ROW TYPE I,
    W_FIELDNAME(20),
    W_PROG TYPE SY-REPID.
    DATA:
    BEGIN OF T_SPFLI OCCURS 0,
    COLOR(4),
    CHECKBOX ,
    CELL TYPE SLIS_T_SPECIALCOL_ALV,
    CARRID TYPE SPFLI-CARRID,
    CONNID TYPE SPFLI-CONNID,
    CITYFROM TYPE SPFLI-CITYFROM,
    CITYTO TYPE SPFLI-CITYTO,
    DISTANCE TYPE SPFLI-DISTANCE,
    END OF T_SPFLI.
    DATA:
    FS_CELL LIKE LINE OF T_SPFLI-CELL.
    SELECT *
    FROM SPFLI
    INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.
    W_COLOR = P_COLOR.
    T_SPFLI-COLOR = P_COLOR.
    IF P_COL IS INITIAL AND P_ROW GT 0.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING COLOR.
    ENDIF.
    FS_FIELDCAT-FIELDNAME = 'CARRID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 1.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'CONNID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 2.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 3.
    FS_FIELDCAT-KEY = ' '.
    FS_FIELDCAT-EDIT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT.
    FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 4.
    FS_FIELDCAT-KEY = ' '.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    LOOP AT T_FIELDCAT INTO FS_FIELDCAT.
    IF FS_FIELDCAT-COL_POS EQ P_COL.
    FS_FIELDCAT-EMPHASIZE = P_COLOR.
    W_FIELDNAME = FS_FIELDCAT-FIELDNAME.
    IF P_ROW IS INITIAL AND P_COL GT 0.
    MODIFY T_FIELDCAT FROM FS_FIELDCAT TRANSPORTING EMPHASIZE.
    ENDIF.
    ENDIF.
    ENDLOOP.
    FS_CELL-FIELDNAME = W_FIELDNAME .
    FS_CELL-COLOR-COL = 6.
    FS_CELL-NOKEYCOL = 'X'.
    APPEND FS_CELL TO T_SPFLI-CELL.
    IF P_ROW IS NOT INITIAL AND P_COL IS NOT INITIAL.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING CELL.
    ENDIF.
    FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
    FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
    FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
    FS_LAYOUT-F2CODE = '&ETA'.
    W_PROG = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_PROG
    IS_LAYOUT = FS_LAYOUT
    IT_FIELDCAT = T_FIELDCAT
    TABLES
    T_OUTTAB = T_SPFLI
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2

  • Help Needed Badly. Troubles with exporting video...

    Hello, I created this account pretty much just for this problem, and I'm running under a very tight timeline so please if someone could give me an answer it would be very much appreciated. I have spent 8 hours over the past two nights as well as 4 hours today reworking, trying different things and combing the online community for any others experiencing these problems and/or solutions, so I am extremely stressed and tired if you could bare with me. So here it is:
    I am editing and compiling a theatre production into a movie. I shot the show three times using a Canon HV30, imported the footage on a school computer (iMac, using iMovie '06), exported it in quicktime onto an external HD, brought it onto my computer (which, stupidly, has no firewire). The total file size was 7 hours of footage (85GB), and as a result my HD has about 300MB left on it, and has been excruciatingly slow. I have finished editing the movie, and I am now attempting to share it. All of the sources I have read tell me to share it in Media Browser, which will be accessible from iDVD. I attempted this many times, however I received multiple different error messages, only after watching it 'working' for 4 hours. Some have said that there was no virtual memory left (even after emptying the cache), some said that there wasn't enough HD space left, the exporting had encountered an error, error messages -50, -49, -48, and -47, and the most prominent one that I have been receiving told me that there had been a "parameter error" or something.
    After researching online, I found that the '-50' error messages had to do with exporting to a MSDOS HD, which made sense because I was attempting to export to my iPod (formatted in Windows). My latest efforts have been trying to export it onto my HD, which is formatted for OSX, and has 350GB left on it. And yet, all of the problems persist (including error -50...?) any help would be greatly, greatly appreciated, as the DVD was due two days ago.
    -Sean

    +"Alright, so I moved over the footage and deleted it off the internal..."+
    Did you move the Events using iMovie? If not, the project pointers become invalid, and you would get the error you did. While moving the event using iMovie, you don't need to "delete" anything!
    Couple of options for you to recover from this.
    A> (Slower) Move the Events back to the internal HD, and use iM to move the Event to the Ext HD.
    B> (Faster, but convoluted) Create an alias for the specific Event folder (now on your ext HD/iMovie Events folder) under your local HD's iM Events folder. IM will now be able to "see" the files on the internal HD, even though they're stored on the Ext HD.
    From the Help File: "To keep an item at its original location and put an alias for it in a new folder, hold down the Command and Option keys while you drag the item."
    Sorry you're having to jump through hoops to get this working...

  • Basic Help Needed - Problems with Cells

    I have created a table that is only 1 column wide and 2 rows
    high, I have put text in the top cell and an image in the bottom.
    The cell padding and spacing are both set to "0"
    In Dreamweaver the image is directly underneath the text with
    no gap - which is how I want it; however when I view through a
    browser i.e. Firefox or Explorer, the cells are stretched in height
    so that there is a massive gap.
    Does anyone know what exactly is happening and how I can
    rectify it so that the browser shows what I see in
    Dreamweaver?

    Let's see your code, please.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Diamonkn" <[email protected]> wrote in
    message
    news:fvhoiv$s4p$[email protected]..
    >I have created a table that is only 1 column wide and 2
    rows high, I have
    >put
    > text in the top cell and an image in the bottom. The
    cell padding and
    > spacing
    > are both set to "0"
    >
    > In Dreamweaver the image is directly underneath the text
    with no gap -
    > which
    > is how I want it; however when I view through a browser
    i.e. Firefox or
    > Explorer, the cells are stretched in height so that
    there is a massive
    > gap.
    >
    > Does anyone know what exactly is happening and how I can
    rectify it so
    > that
    > the browser shows what I see in Dreamweaver?
    >

  • Help using -replace with wildcard characters, specifically braces

    Hello all,
    Needing help in using -replace with literal wildcard characters, specifically the braces characters. From reading old posts online this seems to have been a notorious shortcoming of PowerShell, but not sure if it's been resolved or not. My simple
    code tries to remove the braces as follows (would like to keep the foreach loop and everything as is if possible):
    $string = "test[]"
    $braces = @("``[","``]")
    Foreach($brace in $braces){
    If($string -like "*$brace*"){
    $string = $string -replace ($brace,"")
    write-host $string
    This code gives an error at the -replace line, saying "The regular expression pattern `] is not valid." I'm not sure how to pass the literal brace characters to the -replace parameter? Can this be done?

    -like is a wildcard operator (it recognized wildcard patterns like * ,? and [a-z].
    For a regular expression you use the -match operator.  
    Wildcard patterns and regular expressions are not interchangeable.
    See:
    get-help about_wildcards
    get-help about_regular_expressions
    for an explanation and examples of each one, and 
    get-help about_comparison_operators
    for examples of using -like and -match.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Help needed imediately with photos in swf project!

    Firts of all thanks in advance.
    Ive made a website with flash. I have 6 photos as thumbnails that are buttons. I want to know , when a thumbnail is clicked how to activate lightbox/flashbox to bring up the bigger image via light/flashbox. What function to I need to apply in the actionscript window to the thumbnail that is converted to a symbol as a button
    I am using Flash CS5 and actionscript 3.
    Please any help would be greatful. Ive been seearching and trying for 3 whole days with no luck

    Give a event listener to the btns,
    btn.addEventListener(MouseEvent.CLICK, openbigimage);
    function openbigimage(e:MouseEvent):void
    //write your code for opening big image here
    //Look this for reference
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispa tcher.html#addEventListener%28%29
    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/MouseEvent.html

  • Fill table cells with color % depending on cell content

    Hi.
    I'm working on a document with a lot of tables filled with percentages. The tables are originally on a Word document and the table cells are tinted according to their content: a value of 20% on the cell corresponds to a tint of 20%. This is done automatically on the Word document through a conditional formatting option that applies a graded color scale. Is there any way to do this in InDesign? I tried placing the tables and tried all options, but the color is not imported. Perhaps a script or a GREP style?
    Thank you.

    Conditional formatting in Word is done via formula, but in Excel it is handled more "on the surface" and Excel's conditional formatting carries into InDesign nicely via Place or Paste. It could be worth considering moving those tables into Excel.
    InDesign doesn't do this kind of formatting as a native function, but it couldn't hurt to ask about possible scripted solutions in the Scripting Forum.

  • Urgent Help needed - BADI's in Infospoke

    Hi,
    My Scenario:
    I am pulling data from master data using infospoke into Application server. I need some kind of easy transformations during this stage.
    I got ZSTATE field in my data and I need to restrict my output to only certain states(Ex: NJ,CA, TX , MNetc). Since I can't give those selection conditions in infospoke I need to try BADI. I created a BADI and have target and source structure. Can anyone write me small code for this to eliminate other states and allow NJ , CA, MN, TX etc.
    Source structure: /BIC/CYZZTEST
    target Structure: /BIC/CZZZTEST
    infospoke: ZZTEST
    Field: Zstate
    Class:ZCL_IM_ZZTEST
    Method:IF_EX_OPENHUB_TRANSFORM~TRANSFORM
    Full points to helpful answer!!
    Anil.

    The problem is cross user too - I have two user files on the machine and the same thing happens regardless of which user file I'm working in.
    That points to s 'system-wide' issue.
    Try resetting your SMC.
    Resetting the System Management Controller >>
    Also, you could try booting from your install DVD and see if it does it there. If it does not, it's more than likely a software issue and an Archive and Install should fix it.
    Mac OS X: About the Archive and Install feature >>
    -Bmer
    Mac Owners Support Group - Join us @ MacOSG.com
      Mac611 Mobile Mac Support - about.Mac611.com
       iTunes:MacOSG Podcast | YouTube.MacOSG.com
                       An Apple User Group 
    Have an iPhone or iPod touch? Enter Mac611.com in Safari on it for 'mobile Mac support.'

  • Help needed working with layers and exporting from acrobat3d

    hi, i am repostng this message becaus eihad no success last time, and I am working under a tight deadline for a school project. any help will be tremendously appreciated
    I received an Acrobat 3d file with a model that was originally created in CATIA v4 embedded in it.
    I need to export the model for use in rhino. Currently the model size is enormous as an IGES that Windows runs out of memory when attempting to open. This is a bit wasteful since I do not need all of the model, I just need a layer of it. I noticed that when exporting to IGES you have the option to export hidden or not, and I have hidden the layers i do not need (via Isolation) and still I get the whole file.
    Is there a way I can do this? export the file With the layers under the model tree? or is there a way I can delete a layer? or how can I make the hidden object feature work when Exporting IGES as not to get the things I dont need?
    I read that you can open the model in Toolkit to edit it but it wont let me, open it... no "edit 3d in toolkit" option and when i open the pdf in toolkit it says unknown file....
    is there a way i can open the embedded model in CATIA again?
    thanks for the help

    Please email me your contact information at [email protected] and I might be able to help you.
    Thanks.

  • Eclipse error | Help needed badly

    Hi,
    My Eclipse was working properly a couple of days back but suddenly It's stopped working and gives me an error : "workspace does not contain a main type,Do you have a public void run method"
    Now,I think the problem Is some how the jar's that I'm trying to upload aren't getting uploaded.
    I say this because a strange problem has arised and I think this might have to do with Eclipse giving the above error.
    This Is what I do to create a new java project
    -Open eclipse
    -save files to workspace
    -click on new > java project
    -Then,give the project a name and then click finish
    -after that I create a new class by right clicking on the project folder > new > class >give the class a name and then click finish.
    -after that I open workspace(thats on my desktop) click on the project folder make a new folder name It "lib" and upload the jar that I need for the project.
    -after this I go back Into eclipse and right click on the project folder and hit refresh,now I see the folder"lib" containing the jar Inside It.
    -I right click on the jar file and select "add to build path",and now theres the Issue comes In.
    I want the jar to Into the reference librarys,because the last time I got the jar In the reference library It worked.
    But this time I can't even manage to find where the reference library Is.
    so when I click on add to build path the jar Instead of appearing in the reference library (which Isn't there) just dissapears.
    I really need to fix this,because I cant test and write code until Its fixed.
    heres a snapshot of how my eclipse framework looks : [http://www.flickr.com/photos/38561743@N03/4122304046/sizes/o/]
    I tried to solve this on my own for hours and hours but It just Isn't working.
    please guys help,I need to solve this.
    Thanks,
    Edited by: Parastar on Nov 21, 2009 7:26 AM
    Edited by: Parastar on Nov 21, 2009 7:27 AM

    Parastar wrote:
    okay guys,I'v tried the eclipse forums for about 24 hours now.
    but no response,those guys are really really slow.
    please,some one here help me out.Quit begging. You've already been told this is not the place for this question. You're complaining about not getting an answer there, and begging people here to answer, as if that vindicates your decision to post here in the first place. But you haven't gotten your solution here either. Which is worse--no answer there, or a bunch of answers that don't help you here?

  • Help needed urgently with Superduper backup of Macbook and external HHD

    My Macbook is doing strange things (not sleeping and turning itself on and off, fans going mad etc) so I want to do a cloned back up before taking it to my Apple Service store. I have downloaded Superduper ready to do this but am not sure how I use this as I have an external firewire drive as well as the Macbooks internal drive. Ideally I want to clone everything in order to make sure I have it all covered. Can I make one cloned backup that will include the external drive and the Macbooks drive onto one hard drive that I will use just for this purpose? Or do I have to use Superduper to clone the macbook and then do a separate backup of the files on my external drive? All my important files are on the external drive (photos, iMovie, documents) and I do have a backup of this on another portable drive but this is now too small to fit any more on and is therefore not up to date so I now need to buy a bigger drive and do a full back up ASAP.
    By the way, I am still using Tiger so do not have Time Machine.
    Also, how do i prepare the new drive? Do I need to partition it to a GUID system for my Intel Macbook first before doing the clone?
    Message was edited by: 12frets56

    I am not clear on how many drives you have, of what type, and how much data is on them and which are empty. Perhaps you could provide a list. You say you have an internal, and an external, both with data. If you want to back up both of these you will need another drive that is at least the size of the current space occupied by the files on your internal and important data external. I am less familiar with SuperDuper than I am with CarbonCopyCloner but for both programs there exists a complete bootable backup clone option which puts everything on a drive (including invisible files from your operating system which are essential for your computer to boot) onto the backup. This will also erase the target drive so you need to have an empty drive (or one where you don't care about the content) for a target. You would back up your internal drive in this manner. Your external drive (unless it has a different boot system on it) you can just copy files over since it is just data. It would be handy at this stage if we knew more about the drives so we can make specific recommendations as to what to copy where, and how.
    Kappy posted a detailed description of drive preparation in [this thread|http://discussions.apple.com/message.jspa?messageID=7009683#7009683].
    Message was edited by: Limnos

  • HELP NEEDED BADLY, creating Block Avoider game.

    Could anyone please help me with creating a game called block avoider, i have a link here to show what the game should look like. I need alot of help with it so if anyone is good a coding and see`s this as an easy project helping me would be greatly appreciated.
    LINK TO SIMILAR GAME:
    http://scratch.mit.edu/projects/timo4932/82326

    We can help, but we won't do it for you. Start the game, and post a question if you are stuck and need help.

  • Help needed urgently with cc

    i cannot download and open ccfiles on windows 7 premium, im a mature student struggling to get a library of tutorials together to look back on, but cc keeps stopping i cant download update or get new apps, i pay monthly and i'm getting nowhere even after 12 mths i've no library. files are empty and my photoshop never seems to work correctly. If i cant get this sorted in some way i will be giving up the ghost, ive had enough of struggling with what is supposed to be so easy to do, my confidence as now reached rock bottom.
    If theres anyone out there that  can help, in plain english as i'm no expert. Please! you are most wellcome to talk as much as you want, i will be eternally gratefull....Norma R

    This is an open forum with a mix of program users and Adobe staff, not Adobe support... you need Adobe support
    Adobe contact information - http://helpx.adobe.com/contact.html may help
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"

Maybe you are looking for

  • I need to locate my children's iPhone...

    Is it possible to set up "Find my iPhone" for me to be able to locate my children's iPhone if they've already set it up for themselves?  In other words, can one iPhone be set up by two individuals with separate "Find my iPhone" accounts, i.e. my chil

  • Receiver Module Configuration Issue

    Hi All, I have done the following Module Configuration in Receiver JMS Adapter, but facing issue in the Length of the Flat File received in JMS. it is having only 512 characters, i got clue that is because of   localejbs/SAP XI JMS Adapter/ConvertMes

  • Batch determination in Process Order

    Hi Guys I am doing the automatic batch determination on the process order release. It gets rejected and the error is CO 691: You must enter the batch for material 1025301 Now when I do the manual batch determination in the process order. On clicking

  • What upgrade do I buy for final cut studio

    I have older final cut studio, it included final cut pro 5 and DVD pro 4, motion, soundtrack pro etc. What upgrade should be purchased for the final cut studio. I presume it was studio 1 since it just says final cut studio......

  • Gradient-Layer with Creative Suite SDK

    Hi, i wanna create a gradient-layer with the Creative Suite SDK for AS3. Does anybody have a hint for me, to master this task?