Using colors in Jtable

I have a JTable which will show up several records. For ease of distinguishing between the various categories to which the records belong, I wish to differentiate between the categories with different colors. For eg I will use red color for records that need immediate attention, green colors for records that are perfectly OK and so on. Can somebody suggest me how should I go about it?
Thanx in advance

You should use a TableCellRenderer and set the colour depending upon the object that you are rendering. For more information, see the How to Use Tables tutorial; you'll find a link to it in the API documentation for JTable.

Similar Messages

  • How to get the default selection color from JTable

    Hi, there,
    I have a question for how to get the default selection color from JTable. I am currently implementing the customized table cell renderer, but I do want to set the selection color in the table exactly the same of default table cell renderer. The JTable.getSelectionBackgroup() did not works for me, it returned dark blue which made the text in the table unreadable. Anyone know how to get the window's default selection color?
    Thanks,
    -Jenny

    The windows default selection color is dark blue. Try selecting any text on this page. The difference is that the text gets changed to a white font so you can actually see the text.
    If you don't like the default colors that Java uses then use the UIManager to change the defaults. The following program shows all the properties controlled by the UIManager:
    http://www.discoverteenergy.com/files/ShowUIDefaults.java
    Any of the properties can be changed for the entire application by using:
    UIManager.put( "propertyName", value );

  • How to change the particular column background  color in jTable?

    I am woking with a project, in which I am using a jTable. Then
    How to change the particular column background color in jTable?

    Use a custom Renderer. This is the JTable tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • Setting row color in JTable

    I am trying to display some rows in a JTable in a different color regardless of selection status. The row color criteria would be from data from the object in the row, i.e., given a certain status of a record, I would want to show it as red instead of black.

    A few optimizations:
    class StatusColorRenderer
    extends DefaultTableCellRenderer
        public StatusColorRenderer()
            // super(); not needed, call by default
            setOpaque(true);
            // DefaultTableCellRenderer returns itself as a CellRenderer Component, it extends JLabel so you can call setOpaque on it
    // since this method is called at every paint for every cell it should be HIGHLY optimized
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        Component c = super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column);
        MyObjectClass myObject  = ( MyObjectClass ) myTableModel.getMyVector().elementAt(row);
        <SomeClass> myStatus = myObject.getTheStatus();
        if ( myStatus.compareTo(Status.BAD_STAT) == 0)
            c.setForeground(Color.red);
        else if (myStatus.compareTo(Status.IN_PROGRESS) == 0)
            c.setForeground(Color.green);
        else if ( myObject.getOtherFactor().compareTo(OtherFactors.NOT_DEFAULT) ==  0)
            c.setForeground(Color.blue);
        else
            c.setForeground(Color.black);
        // c.repaint(); NEVER DO THAT
        return c;
    StatusColorRenderer myRenderer = new StatusColorRenderer();
    // only one instance of the renderer
    for ( int i = myTableModel.getColumnCount() - 1 ; i >= 0 ; i-- )
       //column = myTable.getColumnModel().getColumn( i );
       myTable.setDefaultRenderer( myTable.getColumnClass( i ),
                                                myRenderer );
    }Comment:
    AbstractTableModel and DefaultTableModel.getColumnClass method returns Object.class, it is used by the JTable to setup the editor and the renderer of a column
    so if you're using the DefaultTableModel and JTable without overriden getColumnClass, you can set a generic renderer for your JTable by using:
    myTable.setDefaultRenderer( Object.class, myRenderer );

  • Use Color or Magic Bullet Looks for complete grade and effects?

    I am a long time MB Looks user - not heavy dosages but I do find it easy and fast as it keeps you inside FCP and along with the 3-Way CC it was efficient.
    I am nearing an edit on a 80 minute documentary which involves going from color to clips converted to black & white and sepia tone for effect. I am thinking to use Color workflow for the entire color grade and effects.
    Does Color dispense the need for Looks altogether? I have used color a few times now but not on a complete feature length, so I would need to sharpen my knowledge.

    Jon Braeley wrote:
    Does Color dispense the need for Looks altogether? I have used color a few times now but not on a complete feature length, so I would need to sharpen my knowledge.
    Color, MB Looks, FCP's 3WCC are all arrows in our quiver. We don't need to give one up to use another.
    I'm working on a doc now (it's rendering out in Color as I type this) that has "Hero" shots being treated in MB Looks. But I use Color to even out all those Hero shots so the MBL settings I'm using will be applied consistently. But even then I find it useful to to precede MBL with a 3WCC so I can easily adjust the tonality, saturation, and color palette of the shot without having to step back into the MBL interface.
    I can definitely guarantee that I couldn't have graded this show in 2.5 days if I just kept myself to using only the FCP interface. Even with the prep time for the Color round-trip - I get better results faster...
    - pi

  • Plz tell me how to use JSpinner with JTable

    I have retrieve records from database but as the number of records(rows) are more than 1000 , i want to use JSpinner with JTable . plz solve my problem by giving the appropriate code for the same.

    hi
    check this links
    http://www.exampledepot.com/egs/javax.swing.table/CustRend.html
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    hope this will help you.. this explains exactly what you want.
    regards
    Aniruddha

  • What am I missing out on using color on 15" MBP (1400x900) monitor?

    Minimum recommended resolution: 1650x1050
    Should I trade the 15" in for 17" model (Just bought it)? I'm a complete beginner and have never used color before. Basic answers are appreciated. This is not for "TV" production, just small shop jobs and hobby stuff.
    Thanks!

    The single biggest issue is the User Interface, which is locked at a specific size and arrangement.
    In order to pack all the things onto the screen which go into a professional grading solution, the originating application went with a tiny font and big panes, so that users might benefit from a bigger image and a somewhat effective drag-space for the value remapping tools.
    If its for personal entertainment, you really don't need much more, but a single-screen presentation will amplify its own deficiencies in fairly short order...
    Consider, though...
    If you aren't interested in a lot of extracurricular headaches, the three-way inside Final Cut may be more effective in the long run -- no round trip, no rendering new media, no reconnection problems, no hidden gotchas with codec, imbedded incompatibilities within sequences and so on and so forth.
    jPo
    Message was edited by: JP Owens

  • Does Grayscale printing in Canon MP 287 uses color ink also???

    Hi,
    I want to know that using the printer in grayscale mode uses color ink or not for printing????

    So I wonder if my B&W docs have been printing from the color carts and not the pigment black cart. Might this be what's happening? Is there any way to get PSE to use the pigment black cart? Or is something else happening?
    Yes, this is very common with most printers now. They blend colors to get a good black. Does your printer have a grayscale mode option?

  • How to use colors in a progressbar

    hi!
    can you please telle me how to use colors in my application, i mean how should i use a color as a parameter such as :
    progressBar.setBackground(Color);
    in this examlpe, how shoul i pass the paremeter? in which codification, shall i pass it like this way :
    progressBar.setBackground(white);
    or shall i pass it in an other way !!
    please try to help me !

    Color.white, Color.red etc.
    http://java.sun.com/j2se/1.4.1/docs/api/index.html

  • How to use checkboxes in jtable ?

    I am trying to use checkboxes in
    JTable,I set the property in the jtable column to boolean.The proplem is that i do no know how to use this property in java program.My intension is that,I will have a java form and a java button on it,by clicking the button, i will have to write a code,for example a code that fetches records from a table and displays them on the jtable(on the user interface),when I select the check box corresponding to any row,It should let me either delete or edit that row and this modification has to be reflected to the table in the database. At this time,i can fetch and display but i can not delete or modify any row because I do no know how to use the check box inside the jtable.
    Thank you for your help!

    Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5273661&tstart=0

  • How to use AbstractTableModel in JTable

    hi
    i want how to use AbstractTableModel in Jtable
    plz give code

    Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5273661&tstart=0

  • Using color statement

    Hi All,
    I have one internal table , in which i have only two fields of type char15.
    I want to have the contents of first field in black color (by default it is black) and corresponding contents of second field in Red color.
    Please help me in solving it such that second field contents are displayed in Red color on output screen.
    We can use color 6 inverse on for red color text.but how to insert entries in table in red color or display them in red color.

    Hi
    Be more clear about your requirement. where exactly you want the color ? which kind of screen..
    Check out below code..
    REPORT ZTEST.
    WRITE : SY-DATUM COLOR 6 INVERSE ON.
    Hope it will solve your problem..
    Thanks & Regards
    ilesh 24x7

  • Can i convert a non layered file to a layered file bases on used colors?

    can i convert a non layered file to a layered file bases on used colors?

    I have heard questions like this before.
    Some people seem to think that each colour should be on a separate layer.
    I hope you are not one of them, because it is a complete misconception and defeats the object of Illustrator’s object stacking system.
    Why do you think you need to collect objects of the same colour onto separate layers?

  • Newbie Problem, White edges when using colors?

    Hi, I am new to illustrator, and this problem has been bothering me forever. I have googled beyond belief, but no answer. Maybe I am using the wrong terminology? Not sure. But overall, when I create things in illustrator, and use color, there are white edges around everything. Example below.
    Also the colors I choose don't seem to be the ones that show up. Like, for the example above, I chose a deeper purple, but a lighter purple came out. I guess illustrator is A LOT different than photoshop.

    well, i recently had something like that too.
    I just couldnt figure out why it was showing up.
    Untill i began looking at the layers.
    It seemed that somehow some layers got duplicated and stuff.
    So i recommend that you have a look at your layers and check for unwanted duplicates.

  • Using Color Lookup Tables with cwgraph3d

    Hi,
    When searching old forums and other references, I can only find information regarding using color lookup tables in labview and I am using VB6.
    I want to let the user to pick a given amount of colors, have this turned into a gradiant over a table of size 256, and then using the custom colormaptstyle in my 3d graph. I want to be able to change the palette in real time to change my image. Basically I want to have the color palette screen to show up all the time and that gradiant that appears on the right side(vertically) to be my new color lookup table for the image(if that makes any sense).
    Thanks. Any help would be greatly appreciated.
    Kevin
    [email protected]

    Hello Kevin,
    Attached is a small VB6 example that uses the CWGraph3D's ColorMap properties. I think this will demonstrate the color lookup table capability that you're asking about, and you'll be able to use this as a building block for your own application.
    David Mc.
    NI Applications Engineer
    Attachments:
    colormap.zip ‏5 KB

Maybe you are looking for

  • Error in running a stored procedure....

    I have a sp that was converted from mssql to pl/sql Oriacle 9i It is basically supposed to find the current id and add one to it and output it.. the error message i get is System.Data.OracleClient.OracleException was unhandled by user code Message="O

  • Acrobat Reader Firefox plugin and permissions

    There must be a simple answer to this, but I can't seem to figure it out... If I open a pdf file in my browser and try to "save a copy", I'm informed I must be super user to do this... I can save the page through the browser's file menu ok, so this i

  • Oracle on Mac OS X Server

    Hello everybody, We are looking for having the Oracle database on MacOSXServer 10.2. Which version of the Oracle database would you suggest for the same ? We currently have Oracle 8i installed in Sun Unix Server and is there a way to move all our cus

  • Laptop squealing/chirping noise

    My product number is E1P05AV. I've had this laptop for almost a year now and have had the hard drive replaced because I thought that it was the cause of this sound. As of right now I have an ssd, so I know that it is not the culprit. I've done some r

  • Any recent intermittent internel outages in NJ? June 28, 29

    Kind of strange and maybe out of the blue.  Is anyone else losing internet connection using the wireless modem in NJ area?  It seems to happen intermittenty 5 min a time.