How to change color of selected label from list of labels?

My Problem is that I have a list of labels. RowHeaderRenderer is a row header renderer for Jtable which is rendering list items and (labels).getListTableHeader() is a method to get the list. When we click on the label this code is executed:
getListTableHeader().addMouseListener(new MouseAdapter()
public void mouseReleased(MouseEvent e)
if (e.getClickCount() >= 1)
int index = getListTableHeader().locationToIndex(e.getPoint());
try
if (((ae_AlertEventInfo)theAlerts.values().toArray()[index]).ackRequiredFlag)
AcknowledgeEvent ackEvent = new AcknowledgeEvent(
this, (ae_AlertEventInfo)theAlerts.values().toArray()[index]);
fireAcknowledgeEvent(ackEvent);
((HeaderListModel)listModel).setElementAt(ACK, index);
catch(Exception ex) {;}
Upon mouse click color of the label should be changed. For some period of time ie. Upto completion of fireAcknowledgeEvent(ackEvent);
This statement is calling this method:
public void handleAcknowledgeEvent(final AcknowledgeEvent event)
boolean ackOk = false;
int seqId = ((ae_AlertEventInfo)event.getAlertInfo()).sequenceId;
if (((ae_AlertEventInfo)event.getAlertInfo()).ackRequiredFlag)
try
// perform call to inform server about acknowledgement.
ackOk = serviceAdapter.acknowledge(seqId,
theLogicalPosition, theUserName);
catch(AdapterException aex)
Log.error(getClass(), "handleAcknowledgeEvent()",
"Error while calling serviceAdapter.acknowledge()", aex);
ExceptionHandler.handleException(aex);
else
// Acknowledge not required...
ackOk = true;
//theQueue.buttonAcknowledge.setEnabled(false);
final AlertEventQueue myQueue = theQueue;
if (ackOk)
Object popupObj = null;
synchronized (mutex)
if( hasBeenDismissed ) { return; }
// mark alert event as acknowledged (simply reset ack req flag)
ae_AlertEventInfo info;
Iterator i = theAlerts.values().iterator();
while (i.hasNext())
info = (ae_AlertEventInfo) i.next();
if (info.sequenceId == seqId)
// even if ack wasn't required, doesn't hurt to set it
// to false again. But it is important to prevent the
// audible from playing again.
info.ackRequiredFlag = false;
info.alreadyPlayed = true;
// internally uses the vector index so
// process the queue acknowledge update within
// the synchronize block.
final ae_AlertEventInfo myAlertEventInfo = event.getAlertInfo();
SwingUtilities.invokeLater(new Runnable()
public void run()
myQueue.acknowledge(myAlertEventInfo);
myQueue.updateAcknowledgeButtonState();
// here we should stop playing sound
// if it is playing for this alert.
int seqId1;
if (theTonePlayer != null)
seqId1 = theTonePlayer.getSequenceId();
if (seqId1 == seqId)
if (! theTonePlayer.isStopped())
theTonePlayer.stopPlaying();
theTonePlayer = null;
// get reference to popup to be dismissed...
// The dismiss must take place outside of
// the mutex... otherwise threads potentially
// hang (user hits "ok" and is waiting for the
// mutex which is currently held by processing
// for a "move to summary" transition message.
// if the "dismiss" call in the transition
// message were done within the mutex, it might
// hang on the dispose method because the popup
// is waiting for the mutex...
// So call popup.dismiss() outside the mutex
// in all cases.
if(event.getSource() instanceof AlertEventPopup)
popupObj = (AlertEventPopup)event.getSource();
else
popupObj = thePopups.get(event.getAlertInfo());
thePopups.remove(event.getAlertInfo());
SwingUtilities.invokeLater(new Runnable()
public void run()
// search vector elements to determine icon color in main frame
String color = getColor();
fireUpdateEvent(new UpdateEvent(this, blinking, color));
// Call dismiss outside of the mutex.
if (popupObj !=null)
if(popupObj instanceof AlertEventPopup)
((AlertEventPopup)popupObj).setModal(false);
((AlertEventPopup)popupObj).setVisible(false); // xyzzy
((AlertEventPopup)popupObj).dismiss();
else
// update feedback... ack failed
SwingUtilities.invokeLater(new Runnable()
public void run()
myQueue.setInformationMessage("Acknowledge failed to reach server... try again");
return;
Code for RowHeaderRenderer is:
class RowHeaderRenderer extends JLabel implements ListCellRenderer
JTable theTable = null;
ImageIcon image = null;
RowHeaderRenderer(JTable table)
image = new ImageIcon(AlertEventQueue.class.getResource("images" + "/" + "alert.gif"));
theTable = table;
JTableHeader header = table.getTableHeader();
setOpaque(true);
setHorizontalAlignment(LEFT);
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
public Component getListCellRendererComponent( JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus)
int level = 0;
try
level = Integer.parseInt(value.toString());
catch(Exception e)
level = 0;
if (((ae_AlertEventInfo)theAlerts.values().toArray()[index]).ackRequiredFlag)
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
this.setHorizontalAlignment(JLabel.CENTER);
this.setVerticalAlignment(JLabel.CENTER);
setIcon(image);
else
setBorder(BorderFactory.createLineBorder(Color.gray));
setText("");
setIcon(null);
return this;
I tried but when i am clicking a particular label, the color of all labels in the List is being changed. So can you please assist me in changing color of only the label that is selected and the color must disappear after completion of Upto completion of fireAcknowledgeEvent(ackEvent);

im a bit confused with the post so hopefully this will help you, if not then let me know.
I think the problem is that in your renderer your saying
setBackground(header.getBackground());which is setting the backgound of the renderer rather than the selected item, please see an example below, I created a very simple program where it adds JLabels to a list and the renderer changes the colour of the selected item, please note the isSelected boolean.
Object "value" is the currentObject its rendering, obviously you may need to test if its a JLabel before casting it but for this example I kept it simple.
populating the list
public void populateList(){
        DefaultListModel model = new DefaultListModel();
        for (int i=0;i<10;i++){
            JLabel newLabel = new JLabel(String.valueOf(i));
            newLabel.setOpaque(true);
            model.addElement(newLabel);           
        this.jListExample.setModel(model);
        this.jListExample.setCellRenderer(new RowHeaderRenderer());
    }the renderer
class RowHeaderRenderer extends JLabel implements ListCellRenderer
    JTable theTable = null;
    public Component getListCellRendererComponent(JList list, Object value,
                                                  int index, boolean isSelected, boolean cellHasFocus){
        JLabel aLabel = (JLabel)value;
        if (isSelected){
            aLabel.setBackground(Color.RED);
        }else{
            aLabel.setBackground(Color.GRAY);
        return aLabel;       
}

Similar Messages

  • How to change color of DHTML sub menu list

    Hi all,
    In my application i am using DHTML submenu list. But I have to change the color of
    the menu list which is selected currently.
    In interactive report how to fix the column width , because if one column has big string it's going to the right side. My requirement is after fixed column width it has to come in the second line.
    pls help me. I am in urgent need.
    thnks
    pnr

    im a bit confused with the post so hopefully this will help you, if not then let me know.
    I think the problem is that in your renderer your saying
    setBackground(header.getBackground());which is setting the backgound of the renderer rather than the selected item, please see an example below, I created a very simple program where it adds JLabels to a list and the renderer changes the colour of the selected item, please note the isSelected boolean.
    Object "value" is the currentObject its rendering, obviously you may need to test if its a JLabel before casting it but for this example I kept it simple.
    populating the list
    public void populateList(){
            DefaultListModel model = new DefaultListModel();
            for (int i=0;i<10;i++){
                JLabel newLabel = new JLabel(String.valueOf(i));
                newLabel.setOpaque(true);
                model.addElement(newLabel);           
            this.jListExample.setModel(model);
            this.jListExample.setCellRenderer(new RowHeaderRenderer());
        }the renderer
    class RowHeaderRenderer extends JLabel implements ListCellRenderer
        JTable theTable = null;
        public Component getListCellRendererComponent(JList list, Object value,
                                                      int index, boolean isSelected, boolean cellHasFocus){
            JLabel aLabel = (JLabel)value;
            if (isSelected){
                aLabel.setBackground(Color.RED);
            }else{
                aLabel.setBackground(Color.GRAY);
            return aLabel;       
    }

  • How to change colors of LCD/VFD controls from SGC-Tek?

    Hi Anybody got idea how to change colors of LCD/VFD controls from SGC-Tek?
    I have tried but could not. When I try to make myself a nest cluster of clusters of LEDs, I can change colours but I can't do the same thing with LCD/VFD controls.
    Please check at LCD/VFD controls
    Clement

    I suspect this repsonse is somewhat mis-leading, the code has no effect on the control other than setting its state, although the route is somewhat tedious for the mod.
    I would imagine that the control is set up so that the pixels didn't move around when they are being used as controls.
    There are nested groups and locks on the controls, which might make the ordering in the cluster easier to manage.
    The following should work....... ;-) it did for me
    Open  your own new VI
    Open the main LCD VI
    Open the Browse VI Hierachy
    Drag and drop the LCD VI onto your own diagram
    Create a cluster from the LCD VI's connector
    Now ungroup the clusters and unlock them (this is tedious) if you create your own then you could be more imaginative in the structure, I leave that for homework.
    Then import a new bitmap (gif) into the control
    Now update the modified contol back into the master control
    ........ Told you it could be done, but I am not sure the pain was worth it.
    BUT
    Try the alternative control..... with colour settings as well, ANY colour and even some size control.
    It was here http://members.lycos.co.uk/sgctek/

  • How to change colors of individual column bar in the same data series

    in mac numbers, how to change colors of individual column bar in the same data series. The entire column series gets selected in the column bars and cannot select to change colors of specifc bars.

    Hi Kiran,
    no its not possible through Theme editor also ,because these colors are coming from Compiler which u are using.
    Regards,
    Govindu

  • How to change color of a button for specific time interval in jsp

    How to change color of a button for specific time interval in jsp.
    Please help.
    Thanks in advance.

    This was driving me crazy, too--and the previous answers did not seem to work. I eventually found that if I click one of the data symbols in the graph in exactly the right spot (see below), it selects only the data symbols and not the line. I can tell this because the little selection dots will be around each data symbol, but no selection dots will be on the line between the data symbols - like the graphic in Yvan's answer. Then and only then will the color symbol in the tool bar show the color of the data symbol, instead of the color of the line. I believe that you then have to first click on the color swatch in the toolbar and then select your color (or choose Show Colors and select from the color tool). Just clicking a color in the crayon box, for example, did not seem to work unless I first clicked on the color swatch in the toolbar, then clicked Show Colors on that dropdown, and +only then+ clicked the crayon or whatever.
    _The right spot to click_ seems to be just above the exact center of the data symbol, at least for the diamond shape symbol that I prefer. Sometimes it takes several tries to hit the right spot. If I miss it, the whole line is selected, which is indicated by the little selection dots on the line, between the data symbols. When I click the right spot, those selection dots go away, leaving only the data symbols selected. Then I can change the color, as described above.
    I hope this works for you too.

  • How to change color of text is value is equal to 0

    how to change color of text or background if value is equal to 0

    HI,
    In Template Builder,Insert the conditional region,there you select the column and give condition is equal to 0 and in advanced enter the following code
    <?if:XMLfield=0?><xsl:attribute xdofo:ctx="block" name="background-color">red</xsl:attribute><?end if?>
    try this it works.
    Regards
    Uday

  • How to Change the Default SSH Port from Terminal ?

    How to Change the Default SSH Port from Terminal ?

    How to Change the Default SSH Port from Terminal ?
    now showing default SSH Port 22 i need change it pls help me how can do

  • How to Change the Default SSH Port from Terminal ? now showing default SSH Port 22 i need change it pls help me how can do

    How to Change the Default SSH Port from Terminal ?
    now showing default SSH Port 22 i need change it pls help me how can do

    How to Change the Default SSH Port from Terminal ?
    now showing default SSH Port 22 i need change it pls help me how can do

  • How to change the status of IDOCS from 29 status to 53

    Guys
    how to change the status of IDOCS from 29 status to 53
    Thanks in advance

    Hi Krishna
    IDOC_STATUS_CONVERT Use this FM and reward me

  • How to change colors in Auction monitor

    Hi Experts,
    Could you please help me on below requirement,
    In Auction Monitor , need different darker colors for tracking bids  because some colors cannot be seen on the screen.
    Could you please guide me how to change colors in Monitor.
    Thanks,
    Pavan.

    Hi Vinay.
    I would like to suggest a couple of references, quite similar to your requirement,
    [SDN - Reference for Different Colors in Single Graphical bar|About Different Colors in Single Graphical bar;
    [SDN - Reference for changing colors for graphs|Anyone used colors in VC?;
    [SAP HELP - Standard Reference for Assigning Colors to Parts of a Graph|http://help.sap.com/saphelp_nw04/helpdata/en/39/cca358576911d1896f0000e829fbbd/content.htm]
    Hope that's usefull.
    Good Luck & Regards.
    Harsh Dave

  • How to change color in BEx Browser?

    Hello Friends,
    How to change color in BEx Browser?
    My browser shows all the report description with pink color. I want to change the color.
    Please let me know.
    Thanks in advance.

    Hello Bhavin,
    It seems the patches for BW Add-On are being kept pretty much in sync for 6.20 and 6.40 (i.e they seem to be released at around the same time, even that the patch level numbers are different).
    However, at BW Add-on Patch level 4 on a SAPgui640 machine, we didn't have the "pink font" problem.
    It may be that BW 3.5 Add-On patch 6 will have a similar effect for you - it may be worth trying.
    Here is the link to the BW3.50 patch 6... https://smpdl.sap-ag.de/~swdc/012002523100000108232005D/bw350_6-10001615.exe?_ACTION=DL_DIRECT
    The patch 6 referred to above is for the BW3.50 Add-On - the SAPgui patch is typically a different number (the 11 that you mention is the SAPgui patch level).
    Best regards,
    Pat M.

  • How to change color in the title line?

    Hi experts, How to change color in the title line, i show an image for explained better
    !http://img688.imageshack.us/img688/9259/imagenjar.png!
    thanks

    in Views.css file
    file below object.and change border-color as you desired to reflect.
    .TitleTable {
         font-family: arial, helvetica, sans-serif;
         border-width: 0 0 4px 0;
         border-style: solid;
         border-color: #6666cc; ----> change here.
    hope this helps !
    -Niranjan K

  • How to change Macbook pro MD101Hn/a from 32 bit to 64 bit?

    How to change Macbook pro MD101Hn/a from 32 bit to 64 bit?
    Adobe softwares needs 64bit softwares to install and access........

    Please read this:
    http://support.apple.com/kb/ht3696
    Ciao.

  • How to change the language of CS6 from Chinese to English?

    Dear Sir / Madam,
    How to change the language of CS6 from Chinese to English?
    Please give me advice.
    Many thanks,
    Eddie

    Language depends on what version of license you've bought. If you've bought a 'Chinese' license, you're stuck with 'Mandarin' or 'Cantonese' UI language.
    If you purchased a Multi-lingual license (which I doubt they sell these days) and if you did install the 'optional language packs' when installing Photoshop, go to Photoshop Preferences (Edit > Preferences in Windows, Photoshop > Preferences in Mac) > Interface > UI Language - change here.
    Also, keep in mind that if you do change the language with multi-language installation or change your locale, Photoshop may ask you to re-enter and re-activate your license.

  • How do I download only selected audiobooks from iTunes to my iPod.? I don't want to download the whole library..i have an iPod classic and Mac laptop with the latest ios.

    How do I download only selected audiobooks from iTunes to my iPod.? I don't want to download the whole library..i have an iPod classic and Mac laptop with the latest ios.

    If you check songs, simply sync the entire library.
    But I highly recommend (and it is far simpler) to create a playlist (or multiple playlists) and select only that playlist to sync.
    Leave everything checked.
    Then simply add/remove from these playlists and sync away.

Maybe you are looking for

  • FEATURE REQUEST: Enhanced Texture Options in FW

    Recently, a forum user was asking how to change the color of a texture in Fireworks to red or blue. In particular, he/she was struggling with attempting to apply a texture to a white object, and it wasn't showing up. http://forums.adobe.com/thread/10

  • How do I read in a .bmp file?

    How do I read in a .bmp file to a program that uses an ASCII file? Is it possible to change the file to ASCII prior to reading the file into the program? Thanks for all your help!

  • Western Digital HD choice, somewhat directed towards the hatter

    I have two 250GB drive in my system: the stock seagate 250 GB, and the slowest western digital 250 GB kinda "budget" drive. The budget drive was given to me.. I would really like better performance under heavy high definition audio tracking with samp

  • MM_rs.Requery SQL ASP Error

    ' reset the cursor to the beginning   If (MM_rs.CursorType > 0) Then     MM_rs.MoveFirst   Else     MM_rs.Requery   End If I put my Access 2003 database in SQL 2008. I keep getting the following error: Microsoft OLE DB Provider for SQL Server error '

  • Master (Multi Records) Detail Report (Help Required)

    We need Help for Master Detail Report that returns information for all departments and their employees. e.g. Page-1 master Record: Accounts Depts Detail Detail Record: Accounts Empoyees Detail Page-2 Master: Department-2 Detail Detail: Department-2 E