Changing the color of the column in a JTable based on the selection (mouse)

Hi,
I want to change the color of all the cells in a column based on the mouse clicked event.
I have managed to select the entire column. And, even, I have found a working example in the internet. But I don't understand why in my case it doesn't work.
This is the code (an inner class for a TableCellRenderer):
class MCTableCellRenderer extends JLabel implements TableCellRenderer {
          private static final long serialVersionUID = 1L;
          @Override
          public Component getTableCellRendererComponent(JTable table,
                    Object value, boolean isSelected, boolean hasFocus, int row,
                    int column) {
               setFont(table.getFont());
               if(value instanceof Double){
                    setHorizontalAlignment(SwingConstants.RIGHT);
                    DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance();
                    numberFormat.applyPattern("#######.#");
                    String val = numberFormat.format(value);
                    setText(val);
               if(isSelected){
                    setBackground(Color.RED);
                    System.out.println("is selected");
               else{
                    setBackground(Color.BLACK);
                    System.out.println("is not selected");
               return this;
    }I have set opacity to true for the contentPane, but without any result.
Any advice will be very apreciated.

Problem solved.
My Renderer should have extended the abstract class DefaultTableCellRenderer.
class MCTableCellRenderer extends DefaultTableCellRenderer {

Similar Messages

  • How can I change the color of a column header?

    I need to change the color for some column header, how can I do it in webdynpro ABAP? Is it possible?

    hi ,
    i have used in alv....
    <font color="RED">text</font>
    but i think it is not possible to change the colour in table ui element.
    regards,
    sahai.s

  • 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 have been having a issue with getting the colors on my monitor to match the colors fro my print lab. I now have the monitor calibrated to match the prints but when I open elements it doesn't use the same colors. If i have it use the calibrated profile b

    I have been having a issue with getting the colors on my monitor to match the colors fro my print lab. I now have the monitor calibrated to match the prints but when I open elements it doesn't use the same colors. If i have it use the calibrated profile by changing the color management settings, the color picker no longer shows true white or black. How do I get elements 12 to honor the new calibrated settings?

    Ok so I've done what you said and this is what it's come back ....
    I don't know that these are the errors , but they're the things which don't look right ...
    Throughout the shut down there is a recurring line ;
    It says ;
    Com.apple.launchd 1 0x100600e70.anonymous.unmount 301 PID still valid
    Then there are 2 more which I think are related ;
    Com.apple.securityd 29 PID job has I overstayed its welcome , forcing removal.
    Then the same with fseventd 48 and diskarbitrationd 13
    Oh and on Launchd1 : System : stray anonymous job at shut down : PID 301 PPID13 PGID 13 unmount...
    Then the last process says "about to call: reboot (RB_AUTOBOOT).
    Continuing...
    And stops ...
    Hope this means something to you ... Thanks again for your help so far :-)

  • Setting the Size of a Column in a JTable

    Hi there,
    does anybody knows a way how to set the size of a specified column in a JTable without changinge the size of the other columns?
    thx anyway
    Errraddicator

    You've got to change the JTable's column resizing policy to prevent the other columns resizing:
    JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)Otherwise all the columns will be adjusted to fit into the width of the table - changing one column would have to result in at least one other column changing!
    Hope this helps.

  • How to get all the values in one column of a JTable

    How to get all the values in one column of a JTable as a Collection of String.
    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column.

    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column. You could always write a custom TableModel that stores the data in the format you want it. It would probably be about 50 lines of code. Or you could write a loop in 3 lines of code. I'll let you decide which approach you want to take.

  • The ability to measure cash in and outflows based on the Profit Centers

    Hi,
    As you may be aware, we are currently undertaking a global project to split our Balance Sheet based on the divisional structure (Profit Centres in SAP).  The splitting of Receivables and Payables by Profit Centre. We have an additional requirement in the area of cash flow. What is required is the ability to measure cash in and outflows based on the profit centre that the movement relates to.
    Please help me on the above issue.
    Regards
    Srinivas

    Ok closing based on my research
    It is often not possible to set the size of a buffer so that it never becomes full. Above a certain size, which is greatly dependent on the hardware and the operating system, the performance advantage of the buffer is canceled out by increased operating system paging. A buffer that occupies too much main memory forces the operating system to perform expensive paging.

  • I want to implement three level Horizental navigation on the top navigation and menu items are created based on the data available in a SharePoint List.

    Hi All,
    I want to implement three level Horizental navigation on the top navigation and menu items are created based on the data available in a SharePoint List.
    Implement this requirement through customization, how can i start any help
    Thanks

    Hello,
    You can follow these links to get the result that you want. You can get the desired result either using the custom list or a site map. Please make sure when you edit the master page, dont work on the original v4.master. Always make a a copy and then work
    on it.
    This link will show you how get that navigation using a list.
    http://www.bitsofsharepoint.com/BlogPoint/Lists/Posts/Post.aspx?ID=60
    This link will show you how get that navigation using a sitemap.
    http://www.sharepointdiary.com/2012/01/custom-top-navigation-using-sitemap.html
    Please mark as "Answered" if this helped you.
    Thanks,
    norasampang

  • How to make the name of a column apear as many times as the column on page

    Hi,
    This is what i want to do:
    I have a basic report looking like this:
    <Column name>
    value 1
    value 2
    value 3
    value n
    Since the column is small it can fit in a page more then one time. I know how to make it print more then once: i switch the repeating frame to print down and across and i modify the frame that contains it so the horizontal elasticity is variable.
    After these changes my report looks like this:
    <Column name>
    value 1-----------------------value n+1-----------------------value m+1
    value 2-----------------------value n+2-----------------------value m+2
    value 3-----------------------value n+3-----------------------...
    value n-----------------------value m
    What i want is my report to look like this:
    <Column name>-------<Column name>------------<Column name>
    value 1-----------------------value n+1-----------------------value m+1
    value 2-----------------------value n+2-----------------------value m+2
    value 3-----------------------value n+3-----------------------...
    value n-----------------------value m
    Would welcome any advice on how to achieve this please.
    Thank you.

    Hi,
    I will suggest a solution which may appear not simple. I do not know. Il did use this method, because a Government pre-printed tax form can print six values (in colum way) each page and it was not just esthetique question.
    1. Seams that you can know in advance the max number of column according to the width of the page and the length of the column.
    2. You can assume that you have x column at max by ligne
    3. Transforms your N rows in a table of M rows, each one with x columns : you will have N/x + N mod x
    4. I did this transformation using PL/SQL piplined function to transform rows to columns (by x)
    5. You base your report on the Pipelined function using select ... from Table (fnc_....) syntaxe
    6. make your vertical elasticity to variable and horizontal to fixed
    7. Put six labels on the top of your repeating frame (within a normal frame)
    I agree, it's not the solution if the requirment is just esthetic.
    Hope it helps.
    Mohamed Dadi

  • Why is my calendar not holding the correct color.  I have reset the color of a particular calendar posting and within second the color reverts to purple.

    Why is my calendar not holding the set color.  I have reset the color of a particular calendar and within seconds it reverts back to purple.  I am using ICloud on a calander linked to my IPhone and IPad.

    set them at icloud.com on a computer.  its a work around.  Peace, Clyde

  • Updating the particular row and column in a JTable

    Hi,
    I have a JTable which is having fixed number of columns. When i am trying to update a particular cell in the table
    during programm execution i am not able to do it.
    I am getting the row number and column number correctly. But when i am going to set the data it is not setting at the same row. It is setting some other row according to the m_index (according to the sorting).
    i am doing :
    JTableModel model = (JTableModel) m_TablePan.getTableModel();
    model.setValueAt(savedData, row, column);

    See the convertXxxIndexToView and convertXxxIndexToModel methods.
    db
    Edited by: Darryl.Burke -- wrong methods suggested
    Edit2: Evidently lipumama doesn't follow up on many questions posted.
    One for the blacklist.

  • How to disable/enable the cells for editing column wise in JTable in java?

    Hi All,
    Can any one tell me how to disable the cells for editing by column wise in JTable?
    Here depending upon the radio button selected, I need 2 disable some columns for editing
    and enable some columns for editing?
    how can I do tat using JAVA?
    Any sample code is of great help to me.
    Thanks in Advance

    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    ~

  • Why does the DB Tools List Columns.vi only report -1 for the defined column size?

    I am using LabVIEW 8.2.1 with the database connectivity toolset with an SQL Server 2000 database. I would like to see how large a full record could be, so I used the DB Tools List Columns.vi in the database toolset. It easilly displays the column name and the column type, but only returns a -1 for the defined size. Of course when I add up the defined size elements, it gives me -351, which is the number of columns in that particular table. The vi I am using is very simple. I open a database connection, retrieve the data, and close the connection. The retrieved data is an array of clusters. I index it by running it through a for loop, and unbundeling each of the three parameters, and reforming arrays at the end of the for loop. This is as about the simplest vi I have ever made, but only part of it works.
    Attachments:
    Table size.vi ‏23 KB

    SciManStev-
              I don't know if this gets you the functionality you want because I don't have access to your file, but I would have code it this way (see attached picture). I would have used a Array to Cluster.vi to convert the column info ouput array into a cluster so I could use Unbundle by name. I think this is what you are wanting because from what I see, you only access the file once everytime the VI runs (right?). Try this and let us  know how it works out. Thanks!!
    Grant H.
    National Instruments
    LabVIEW Product Marketing Manager
    Attachments:
    untitled.JPG ‏29 KB

  • Filtering the rows of a JTable based on JCombobox selection

    Hi,,,
    I write an application where I have a combobox contains the JTable first column data when i click on the item it should give me the rows, which contains the selected item as their first column data. I am enable to get the list like that, please, help me in this.........................................
    Thanks In Advance,
    Sun_sgrk

    Hi Albert,
    I write the code like this.............., please, check it, if I am following any where wrong let me know.......
         JComboBox filterCb=(JComboBox)evt.getSource();
            if(filterCb==filterComboBox){
                for(int i=0;i<wtOb.length;i++){
                    for(int j=0;j<4;j++){
                        if(wtOb[0].toString()==filterComboBox.getSelectedItem())
    System.out.println(""+wtOb[i][j]);
    This code I written in netbeans, when I am printing the values of wtOb[i][j] in console its getting the rows, suppose I am selecting the topic as GeneralTopic then its givining me the output as-----
    GeneralTopic
    Dealer5
    Player3
    BlackJack2
    GeneralTopic
    Dealer7
    Player6
    BlackJack
    but I am getting the trouble when i want to show these rows only in my table, please, give me any suggestion or any help to resolve it. I tried with table.setModel also but its not working.
    Regards,
    sun_sgrk

  • How to enable the DFF in OAF page(where Dff is based on the custom table).

    Hi Experts!!
    I am in the process of enabling the dff in OAF page. I am not able to enable the dff if am using the Custom table.
    Ex:
    Assume that my DFF XX_DFF is using the custom table XX_TABLE of att1,att2..
    I am able to enable the dff in OAF page but not able to make those values entered to get stored in the custom table.
    I need helping hands to help me out to get the entered dff values stored in my custom table.
    Kindly provide me the steps so that I can follow up..
    Best wishes,
    Thiru.

    Hi,
    thiru_apps wrote:
    I need to store the captured values of Dff(which was enabled in the seeded page based on the custom table XX_Table) and the same needs to be stored into the custom table xx_Table.
    Basically the entered values for the DFF enabled should have to be get stored in the XX_TABLE(Custom TAble).As per my understands in Standard page u want create some extra fields and those should be save in custom table...is it ...
    For that u r going create stack layout region in standard page via personalization and extend with custom region.
    IF im geting u correctly u need to write code in co and am.
    ---U had already created the components eo vo AM co...
    ---For the custom region in Jdev do the mapping of viewInstacne and view attribute properties for the fields.
    ---In AM:
    public void CreateVo(OAPageContext pageContext, OAWebBean webBean)
    Row hrow;
    OADBTransaction tr=getOADBTransaction();
    EOVOImpl vo=getEOVO1();
    if(!vo.isPreparedForExecution())
    vo. executeQuery();
    hrow=vo.createRow();
    vo.insertRow(hrow);
    hrow.setNewRowState(Row.STATUS_INITIALIZED);
    public void savetr()
    OADBTransaction tr=getOADBTransaction();
    tr.commit();
    In Co ProcessREq:
    AMImpl AM=(AMImpl)pageContext.getApplicationModule(webBean);
    AM.CreateVo(pageContext, webBean);
    In Co ProcessFormREq:
    ---GEt the event of the save button of the standard page
    if(pageContext.getParameter("save")!= null)---DI of the standard page
    AM.savetr(pageContext, webBean);
    Regards
    Meher Irk

Maybe you are looking for

  • Error while saving config in MSY

    Hi, I am working on taking MSA 5.0 SP7 go-live. I am working in MDW. I posted a SDN post long back regarding the custom partner functions in MSA and got it resolved (followed the note 521871). I am trying to do the same in the PROD system and i am fa

  • How to submit values in multiple fragments?

    Hello, I am using Jdev 11.1.1.6 with ADFBC and ADF Faces as technology stack. Let me describe my use case first and then the problem. I have a BTF using page fragment. Let's call this MasterPage.jsff. This MasterPage.jsff has 2 regions, implemented a

  • How to know if an output condition record is ever used in sales docs

    All, I can see some output condition records in table B001. Additional detail of these records is in table NACH. But is there a way to know whether these condition records are determined in any sales docs? In individual sales documents, I can manuall

  • Themes are not present when trying to make a card.

    Themes are not present when trying to make a card.  ??

  • Tri-state pin

    Hi! I'm working with a PCI-MIO-16E-1 DAQ and i want to know if a PFI pin as an output is set to tri-state and to use their corresponding special function signal i have to make a routing, or it's set automaticaly to output the corresponding special fu