Diaplaying color in table

hi i created one panel in my project using netbeans.now i want to display the color in my table i tried but i am getting color code insted of
color ...
here is my code
package pckRender;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.DefaultTableModel;
* @author admin
public class pnlRender extends javax.swing.JPanel {
Object[][] data = {{"Shashi", "24", Color.red}};
String [] columnnames= {"Name", "Age", "Color"};
/** Creates n
* ew form pnlRender */
public pnlRender() {
super(new GridLayout(1,0));
initComponents();
javax.swing.table.AbstractTableModel model = new javax.swing.table.DefaultTableModel(data, columnnames);
javax.swing.JTable table = new JTable(model);
table.setFillsViewportHeight(true);
table.setOpaque(true);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setOpaque(true);
scrollPane.setViewportView(table);
table.setDefaultRenderer(Color.class,
new ColorRenderer(true));
add(scrollPane);
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setLayout(new java.awt.GridLayout());
}// </editor-fold>
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TableDialogEditDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new pnlRender();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
// Variables declaration - do not modify
// End of variables declaration
And To display the Color in tabel i created one class here is that Code
package com.aerron.coconut;
* ColorRenderer.java (compiles with releases 1.2, 1.3, and 1.4) is used by
* TableDialogEditDemo.java.
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;
import java.awt.Color;
import java.awt.Component;
public class ColorRenderer extends JLabel
implements TableCellRenderer {
Border unselectedBorder = null;
Border selectedBorder = null;
boolean isBordered = true;
public ColorRenderer(boolean isBordered) {
this.isBordered = isBordered;
setOpaque(true); //MUST do this for background to show up.
public Component getTableCellRendererComponent(
JTable table, Object color,
boolean isSelected, boolean hasFocus,
int row, int column) {
Color newColor = (Color)color;
setBackground(newColor);
if (isBordered) {
if (isSelected) {
if (selectedBorder == null) {
selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
table.getSelectionBackground());
setBorder(selectedBorder);
} else {
if (unselectedBorder == null) {
unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
table.getBackground());
setBorder(unselectedBorder);
// setToolTipText("RGB value: " + newColor.getRed() + ", "
// + newColor.getGreen() + ", "
// + newColor.getBlue());
return this;
so how to display the Color.
Thank You in Advance

Take a look here, you might find something usefull for you
[All about JTables|http://www.java2s.com/Code/Java/Swing-JFC/Table.htm]
Never forget to use the code tag on your messages, if you dont people will not read your code.

Similar Messages

  • How can i Change Text Color in table

    How can i change the text color i table, the true becoming GREEN, and the text in Fals becoming RED.
    Someone can help me to resolve this problem with a sample, because when i run the program all text becoming green in (TRUE) and than when i chang it to the (fals) all becoming Red.
    Attachments:
    Color.vi ‏38 KB

    Modifying the properties of a control in a subVI do not modify the properties of a different control in the main VI. The data is the only thing passed back from the subVI. To modify the properties of the table in the main, you need to pass a reference to it to the subVI and modify it's properties. I've attached a modified llb that does what you want.
    Attachments:
    Main_color_Table_mod.llb ‏41 KB

  • Coloring a table in one (not too long) line.

    Is there a way of coloring a table or cell a swatch color in one shot without having to go through: bottomEdgeStrokeColor = myColor, topEdgeStrokeColor = myColor, leftEdgeStrokeColor = myColor, rightEdgeStrokeColor = myColor?
    Not the end of the world if not but would be nice

    I got it.
    It's useful if you have a lot of styles with the same stroke color or other property
    Thanks for the giveaway clue
    myDoc = app.activeDocument;
    myColor = app.activeDocument.swatches.item("C=0 M=100 Y=0 K=0");
    magentaStroke = {bottomEdgeStrokeColor:myColor, topEdgeStrokeColor:myColor, leftEdgeStrokeColor:myColor, rightEdgeStrokeColor:myColor}; // sets all edges to color
    myColor = app.activeDocument.swatches.item("C=100 M=0 Y=0 K=0");
    cyanStroke = {bottomEdgeStrokeColor:myColor, topEdgeStrokeColor:myColor, leftEdgeStrokeColor:myColor, rightEdgeStrokeColor:myColor};
    try {myCellStyleMagenta = myDoc.cellStyles.add({name:"myCellStyleMagenta"});}
    catch (exist) {myCellStyleMagenta = myDoc.cellStyles.item("myCellStyleMagenta");}
        with (myCellStyleMagenta){
          bottomInset =1;
         properties = magentaStroke; // applies color to cell style
      try {myCellStyleCyan = myDoc.cellStyles.add({name:"myCellStyleCyan"});}
    catch (exist) {myCellStyleCyan = myDoc.cellStyles.item("myCellStyleCyan");}
        with (myCellStyleCyan){
          bottomInset =1;
         properties = cyanStroke;

  • How can I pop up a Color Selection table?

    When I click on a color box control in the front panel,it will pop up a color selction table.My question is how can I control the pop up of the color selection table in the diagram?for example,if a boolean control is clicked then I want to pop up the color selection table,If the color selection table is an Active Control,what's the name if it?
    Any help will be appreciated.

    Just use a color control.
    Attached is an example. The example run as a dialog box
    Best regards;
    EJV
    www.vartortech.com
    Attachments:
    select_color.vi ‏11 KB

  • Coloring in Table control

    Hi All,
    I have a requirement to show alternate rows of table control with alternate colors.
    Please help on this.
    Thanks in advance.
    Suri

    hi suresh,
    Welcome to SDN forum
    check these links
    Re: Cell color
    Smartforms: Background Color in tables
    ALV : color one cell
    Reward with points if it is helpful
    Cheers
    Alfred

  • Coloring a table cell with swing

    Hello,
    I am trying to write a java program in swing. Basically I am setting up a table and adding labels to the table's cells. Rather than displaying the label, the table is inserting the labels' string value. Here is a compilable example:
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    import java.awt.*;
    public class TableTest extends JFrame {
         private final JTable table;
         private final GridBagConstraints constraints;
         private JLabel makeLabel(Color c){
              JLabel lab = new JLabel(" ");
              lab.setOpaque(true);
              lab.setBackground(c);
              //getContentPane().add(lab, constraints);
              return lab;
         public TableTest() {
            super("Visualizer");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().setLayout(new GridBagLayout());
            constraints = new GridBagConstraints();
            constraints.insets = new Insets(3, 10, 3, 10);
            String[] columnNames = {"RED","YELLOW", "BLUE"};
            Object[][] data = { {makeLabel(Color.RED), makeLabel(Color.YELLOW), makeLabel(Color.BLUE) } };       
            table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setFillsViewportHeight(true);
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
            pack();
            setVisible(true);
         public static void main(String[] args) {
              new TableTest();
    }How do i modify this to actually show the labels? Thanks in advance.

    Why are you putting labels into the table's cells?
    Have a look at Sun's tutorial on tables to see how a custom renderer is used to display particular cells in a certain way. (And also for the whole rendering approach used by tables.)
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer
    (Swing questions are better asked in the Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57)

  • 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

  • What can you do with Color Lookup Tables (CLUT) and other ranges.?

    Ok.... I might be repeating something.... but someone
    suggested to post this as it hasn't be answered....
    Anyway I'm curious on what you can do with Color Lookup
    Tables (CLUT) in Fireworks.... I've been looking for details on
    CLUT, but have only found information on what it's all about....
    Alright, to the point, I'm kind of having some trouble on
    what to do period with them....in the optimize panel in Fireworks I
    saved the Palette, of all the colors I wanted (or so it seemed,
    idk), and made it so it would be for a PNG 32 file... *is this
    suppose to be an .act file too?*.... I then took the image to have
    the colors replaced to the ones I saved in the custom color
    table... so I tried loading the .act file I had saved, that had the
    colors I made for the other image, but nothing happened... so I
    tried doing other various types of files..... I tried doing it as a
    .gif, and it work.... but the thing is I don't want it to be a
    gif... and yes, it is kind of vague, but I really don't know what
    to really do....
    Is there only certain ways that you can load up CLUT files
    into different pictures...?? I want this picture to be a .png file
    too, so is there any way to save the color palette, and load them
    into these type of files..?? or it can't be done with them..??
    overal, I want this image to be .png files... is there any
    tutorial or info on this..?? it would be quite helpful...

    AarokBomB wrote:
    > Is there only certain ways that you can load up CLUT
    files into different
    > pictures...??
    Choose File > Image Preview > Options tab. Set the
    format type to PNG 8,
    GIF, TIFF 8, or BMP 8. Click on the small button to the right
    of the
    Format drop down menu to open the tab options menu. Choose
    Load Palette
    and browse to the .act palette you you have saved. Clock on
    OK to accept
    the changes and close the dialog box. The imported color
    table will be
    applied to the image.
    Linda Rathgeber [PVII] **Adobe Community Expert-Fireworks**
    http://www.projectseven.com
    Fireworks Newsgroup:
    news://forums.projectseven.com/fireworks/
    CSS Newsgroup: news://forums.projectseven.com/css/
    Design Aid Kits:
    http://www.webdevbiz.com/pwf/index.cfm

  • Crash while launching in "building color conversion tables"

    Photoshop CS6 crashes while "building color conversion tables"  I reinstalled the program but it still hangs up at this point.  please help!

    I've only seen 3 things that can cause a crash at that point: corrupt profiles (mostly display profiles), corrupt information coming from the OS about the system profiles, and bad floating point units in CPUs.
    First thing to check is the display profiles. If setting them to sRGB doesn't solve the crash, it might be a bug in the OS profile cache.  And let's hope it isn't the CPU, because those problems are a @$%^@#%# to track down in modern processors.

  • How to set colors to table control?

    Hi all,
    can we set colors to tables columns and rows?? How can we acieve this? Any help please
    Thanks,
    Madhan.

    Hi All
    thanks for your replies..
    data tab type IF_main_view=>Elements_segment.
      data line type IF_main_view=>Element_segment.
      data node_info type ref to if_wd_context_node_info.
      data attribute_info type wdr_context_attribute_info.
      data attr_value type WDR_CONTEXT_ATTR_VALUE.
      data wd_standard_cell type ref to cl_wd_table_standard_cell.
      data component like line of cl_abap_structdescr=>components.
      data wd_table_column type ref to cl_wd_table_column.
      node_info = lo_nd_segment->get_node_info( ).
      attribute_info = node_info->get_attribute( 'CELL_DESIGN' ).
    if component-name = 'SEGMENT'.
      wd_standard_cell->set_cell_design( CL_WD_ABSTR_MASTER_TABLE_COL=>E_CELL_DESIGN-BADVALUE_MEDIUM ).
    endif.
    i am trying to set color for  some colomns, but i am not getting any colors??? anything wrong in this.. please help
    thanks,
    Madhan.

  • How to add colors to table cells

    Hi ALL,
    Does anyone have any idea of adding colors to table cells?For example i am displaying monthly chart in a table view i want to fill the cells with colors when columns are saturday and sunday.
    Thanks in advance

    Hi,
    I want to pass the colors at bean level.For example
    private DefaultTableViewModel createNewTable
                                      (DefaultTableViewModel model) {
            Vector data = createData();
            Vector colName = new Vector();
            /* Define column names */
            colName.addElement("1stColumn");
            colName.addElement("2ndColumn");
            colName.addElement("3rdColumn");
            model = new DefaultTableViewModel(data, colName);
            return model;
        private Vector createData() {
            Vector dataVec = new Vector();
            Vector retVector = new Vector();
            /* 1st entry */
            dataVec.addElement("Row 1, Column 1");
            dataVec.addElement("Row 1, Column 2");
            dataVec.addElement("Row 1, Column 3");
            retVector.addElement(dataVec);
            /* 2nd entry */
            dataVec = new Vector();
            dataVec.addElement("Row 2, Column 1");
            dataVec.addElement("Row 2, Column 2");
            dataVec.addElement("Row 2, Column 3");
            retVector.addElement(dataVec);
            /* more entries */
            return retVector;
    suppose I want to pass the color at Row2,Column1.Can anyone post the sample code ?
    its little urgent.Thanks in advance

  • Getting error while setting color to table rows?

    Hi All
    I am trying to setting colors to table rows based on dropdown value.
    lv_Dropdown vaue =1 i want to set one color, 2-another color like that.
    For this I create attribute CELL_DESIGN of type WDUI_TABLE_CELL_DESIGN in node, and i bind this attribute to every column celldesign property in table. and my code in on select of dropdown.
      data lr_column type ref to cl_wd_table_column.
    data:obj_table type ref to cl_wd_table.
    lr_column = obj_table->get_column( id = 'TABLE_WEEK1' ).
    if lv_dropdown = 1.
       lr_column->set_cell_design(
    cl_wd_table_column=>e_cell_design-badvalue_dark ).
    endif.
    lr_column->bind_cell_design( path = 'SEGMENT1.CELL_DESIGN'  ). ...Giving dump at r_colum = get_column( )
    I follow correct code or not??
    Cheers,
    Venkys.

    Sorry Sarbjeet and baskaran i am not getting,
    I want to set colors to row of a table on dropdown selection. In dropdown i ahve a code like
    DATA lo_nd_segment1 TYPE REF TO if_wd_context_node.
      DATA lo_el_segment1 TYPE REF TO if_wd_context_element.
      DATA ls_segment1 TYPE wd_this->Element_segment1.
      data lt_segment1 type wd_this->elements_segment1.
      DATA lv_segment TYPE wd_this->Element_segment1-segment.
    navigate from <CONTEXT> to <SEGMENT1> via lead selection
      lo_nd_segment1 = wd_context->get_child_node( name = wd_this->wdctx_segment1 ).
    get element via lead selection
      lo_el_segment1 = lo_nd_segment1->get_element( ).
      lo_el_segment1 = WDEVENT->GET_CONTEXT_ELEMENT( 'CONTEXT_ELEMENT' ).
    get all declared attributes
      lo_el_segment1->get_static_attributes(
        IMPORTING
          static_attributes = ls_segment1 ).
    DATA : lv_dropdown type string .
    lv_dropdown =  ls_segment1-segment.
    if lv_dropdown = 1.  SET ONE COLOR TO THAT ROW
    endif.
    if lv_dropdown = 2.  SET ONE COLOR TO THAT ROW
    endif.
    Now what should be the code in WDMODIFYVIEW method to set table row with colors.
    Cheers,
    Venkys.

  • Coloring individual table rows based on a condition

    Hi Experts,
    I have a table bound to a node in the context via datasource property.
    I was trying to color an individual row based on a certain value in the context node.
    Can anyone help my achieve this please?
    For example:
    for( int i=0; i<table.size(); i++)
        if(wdContext.tableNode().getTableElementAt(i).getFieldA().equals("Y"))
            // then color the table row
    Any suggestions?
    M

    Solved.

  • SAPSCRIPT: How change background color cell/table

    Hi!
    How can I change background color cell/table in Sapscript?
    Thanks very much!

    Hi ,
    Normally we use Scripts and smartforms for submitting the output to customers or for tax purpose  and so on,,in such case we wont submit in differnt color other than white and black,so formatting in other colors is not possible in Script and smartforms.
    Please let me know if have any issues on this.
    Thanks and regards,
    Rajeshwar

  • Problem with cfdocument and background colors with table borders

    i am having a great deal of difficulty with cfdocument
    rendering my tables with cells that have background colors. the
    background colors seem to bleed through the table border. a picture
    at 100% magnification can be seen at
    http://www.vitad.com/cfdoc.jpg
    and at 1600% magnification at:
    http://www.vitad.com/cfdoc2.jpg.
    i am attaching sample code of the what generated the pdf in the
    pictures. btw, i am running cfmx 7 with hot fix 2.

    Hi fresher4flex,
    Since you are using the item Renderer for the DataGrid Column try to apply the styles dynamically to the background of your itemRenderer by making using of the rollOver and rollOut events.
    Thanks,
    Bhasker

Maybe you are looking for

  • How can you set the ctxsvr time interval ?

    I would like to know how can i set the time inteval between each update of the Intermadia indexes. Thanks.

  • Service Date Duration

    I have an Object called Service Date in the Universe. In Webi, I created a report with Service Date for a duration of 03/02/2010 - 05/04/2010 by using Service Date as Query filter with in Between Operator. In report it shows the service date duration

  • How can I set the textbox properties to get only integer on netbean?

    I use Netbean GUI and I create the swing textbox how can I set it to enter only Integer I don't want the people to enter the string.

  • Missing Web Items

    Hello, We have migrated from BW 3.0 to NW2004s SP13. The users are complaining that some web items like broadcaster and whatifprediction is not available on portals. 1) What could be the issue with this after upgrade. 2) There is a migration of web i

  • Error in Substitution of  rootAM on OpptyDetPG 12.0.2

    Hi, In Oracle Sales (ASN) , R12 RUP2, Using JDev we are adding a new region with 2 Poplist fields with their own VOs on OpptyDetPG (opportunity Update Page). While Substituting those 2 VOs to the rootAM of the Page. we are are unable Edit the rootAM