How to get default color of a selected row in a JLIst

I have a JList that I am changing the font color for based on a certian situation so I created my own MyCellRenderer to do this. However, when I select an item in the list the row is no longer highlighted. I used the isSelected method to determine if a row was selected and then change the background color of that row. However, I would like the color to be the default color that you get when you select a row in a default JList. I can't seem to figure out how to get that color. How do I obtain what that color is? I found an example where you can get the default color for the background of a button and use that color so I would guess it is something similar to that. My code is below so I hope someone can tell me how to get that color that I want.
Thanks...Chris
class MyCellRenderer extends JLabel implements ListCellRenderer {
     public MyCellRenderer() {
          setOpaque(true);
     public Component getListCellRendererComponent(
         JList list,
         Object value,
         int index,
         boolean isSelected,
         boolean cellHasFocus)
         int index1 = value.toString().indexOf("-");
           String errors = value.toString().substring(index1 + 1, index1 + 6).trim();
         int numErrors = Integer.parseInt(errors);
           if (numErrors > 0)
                  setForeground(Color.red);
                  setBackground(Color.white);          
         else
              setBackground(Color.white);
              setForeground(Color.black);
         if(isSelected)
              //ColorUIResource col = (ColorUIResource)UIManager.getDefaults().get("JButton.background");
              ColorUIResource col = (ColorUIResource)UIManager.getDefaults().get("Button.background");
              setBackground(col);
         setText(value.toString());
         return this;
}

Swing related questions should be posted in the Swing forum.
I would like the color to be the default color that you get when you select a row in a default JList. I can't seem to figure out how to get that colorlist.getSelectionBackground();

Similar Messages

  • How to change the default color of the selected row

    hi all,
    I need to know how to change the default color(yellow) of the selected row in a table component.whether i need to change anything in the stylesheet.If so, where should i make the changes in the stylesheet.
    thanks and regards,
    rpk

    The chart colors are being referred to *'palette.cxml'* file in these directories
    BI_HOME\web\app\res\s_oracle10\chartsupport
    BI_HOME\oc4j_bi\j2ee\home\applications\analytics\analytics\res\s_oracle10\chartsupport
    you can change to your custom colors.
    Restart OC4J and PS to make the new ones work..
    Regards,
    Raghu

  • How to get all the index of "selected rows" in table control?

    Hi Gurus,
    I have a table control, wherein I need to get selected row so that I can get its respective TABIX.
    I know that the event for capturing selected row is in PAI.
    I also ensure that the w/ selColumn name in my screenpainter is exactly the same as my declaration in ABAP.
    TOP INCLUDE
    YPES: BEGIN OF Y_ZQID_CHECK,
            IDNUM           TYPE ZQID_CHECK-IDNUM,
            WERKS           TYPE ZQID_CHECK-WERKS,
            MATNR           TYPE ZQID_CHECK-MATNR,
            LICHA           TYPE ZQID_CHECK-LICHA,
            LIFNR           TYPE ZQID_CHECK-LIFNR,
            ECOA_S          TYPE ZQID_CHECK-ECOA_S,
            ID_STAT         TYPE ZQID_CHECK-ID_STAT,
            ID_DATE         TYPE ZQID_CHECK-ID_DATE,
            FLAG_MAILCOA(1) TYPE C,
            MARK(1)         TYPE C, "Name of w/ SelColumn in ScreenPainter: T_ZQIDCHECK_DISCH-MARK
           END   OF Y_ZQID_CHECK.
    DATA: T_ZQIDCHECK_DISCH TYPE STANDARD TABLE OF Y_ZQID_CHECK WITH HEADER LINE.
    PAI
    PROCESS AFTER INPUT.
    * MODULE USER_COMMAND_9004.
    LOOP AT T_ZQIDCHECK_DISCH.
      MODULE READ_TC_DISCH .
    ENDLOOP.
    module READ_TC_DISCH input.
      DATA: W_LINE_SEL TYPE SY-STEPL,
                  W_TABIX    LIKE SY-TABIX.
      GET CURSOR LINE W_LINE_SEL.
      W_TABIX = TC_ID_ONLY-TOP_LINE + w_LINE_SEL - 1.
      MODIFY T_ZQIDCHECK_DISCH INDEX TC_ID_ONLY-current_line.
    If I am selecting single row, I can properly get the selected index via debug.
    BUG:
    When I'm selecting multiple rows in table control, only the last row is always being read inside the loop of my table control.
    Please see the screenshot.
    [url]http://img268.imageshack.us/img268/5739/tcselectedrows.jpg[url]
    Notice in the debug screenshot, even if it's just in the 1st loop of table control, it automatically gets the 4th table control index, instead of the 2nd one.
    Helpful inputs will be appreciated.
    Thanks.
    Jaime
    Edited by: Jaime Cabanban on Dec 9, 2009 3:16 PM

    Hi,
    Are you sure that you have selected multiple line for tablecontrol in the property window of the tablecontrol.
    Flowlogic.
    LOOP WITH CONTROL TC_01.
         Module Get_Marked.
    ENDLOOP.
    Module Pool
    Module Get_Marked.
    read the data from the internal table where mark  = 'X'.
    this should give you only selected records.
    Endmodule.
    Kindly check the tablecontrol property.
    Regards,
    Ranjith Nambiar

  • How to get the attribute of a selected row in a label

    Hi all,
    I am using Jdeveloper 11.1.1.2 and ADF.
    I have a table with two columns, Id and Name. Furthermore I have an outputText where I would like to see the field Name of the selected Row in the table.
    How have I to set the property "value" of the outputText to do this?
    Thank you
    Andrea

    Hi Andrea,
    If you are using ADFBC, the easiest way is to drop the attribute(Say Name) from the data control palette as outputText component and add partialTriggers property of it to point to table id(to refresh the outputText whenever the row is selected in table)
    Sireesha

  • How to get column value of a selected row of ALV

    Hello ,
    I have application POWL POWL_UI_COMP uses  another component  POWL_TABLE_COMP.
    This POWL_TABLE_COMP uses SALV_WD_TABLE.
    I want to select value of ORDER id and it need to be passed whenever user selects a display order button(Which is self defined function generated in POWL_TABLE_COMP) . I am calling a display order on action of this display button(http://nap60.nalco.one.net:8042/sap/bc/webdynpro/sap/mt_order_app?IV_ACTIVITYTYPE=A&IV_EQUIPMENT=aaaa&IV_ORDERID=90001511&IV_ORDERTYPE=STD&IV_QMNUM=00&IV_TPLNR=00)
    ORDERID is one column value of selected row of ALV table.
    So please can you suggest , how to read ORDERID and pass it to the self defined function..
    thanks in advance,
    Sharada

    Anoop,
    I have plcaed this code in event handler of  on_lead_select.
    Its giving error  the element doesnt exist. 
    static_attributes should give me row data but it's giving short dump saying
    Pl can you suggest.
    data:   set_of_element type WDR_CONTEXT_ELEMENT_SET,
            element1 type ref to IF_WD_CONTEXT_ELEMENT,
            result type POWL_CRESULT_STY,
            table_helper type ref to CL_POWL_TABLE_HELPER,
          context_node type ref to IF_WD_CONTEXT_NODE,
           lt_selected_elements TYPE wdr_context_element_set,
           static_attributes type ref to data.
      table_helper = wd_comp_controller->mr_table_helper.
      context_node = table_helper->get_data_node( ).
      context_node = wd_comp_controller->mr_table_helper->get_data_node( ).
      context_node->get_static_attributes( exporting index = r_param->index
                                          importing static_attributes = static_attributes ).
    thanks,
    Sharada

  • How to get the values of last selected row in Table?

    Hi,
    I have one editable table , where i have Create, Delete and Commit operation on it.
    When i am clicking on Create button it add new row to my table.
    But I want the value of my last selected row from the table in my Bean.
    Can anyone suggest me please....... its urgent
    Jdev:- 11.1.1.0.3
    Thanks,
    Ramit

    just get this code empTable is the table binding
                    RowKeySet rks = new RowKeySetImpl(); 
                    CollectionModel model = (CollectionModel)empTable.getValue(); 
          RowKeySet selectedRowKeys = empTable.getSelectedRowKeys();
          if (selectedRowKeys != null)
                Iterator iter = selectedRowKeys.iterator();
                if (iter != null && iter.hasNext())
                  empTable.setRowKey(iter.next());
                  model.setRowIndex(empTable.getRowIndex()); 
                  Object key = model.getRowKey(); 
                  rks.add(key); 
                    empTable.setSelectedRowKeys(rks); 
          AdfFacesContext.getCurrentInstance().addPartialTarget(empTable);
        public void setEmpTable(RichTable empTable) {
            this.empTable = empTable;
        public RichTable getEmpTable() {
            return empTable;
        }

  • How to get the values of a selected row and edit it

    hi all,
    i am using a table component.I am populating it from the database.i used static text to display the data .i have a edit button in the last column. when i click on it that particular rows data should be shown in a text field in that row itself,so that i should be able to edit it and then if i save it it that row should change to statictext with the updated data.
    please provide a solution for this...
    regards,
    rpk

    Hi Andrea,
    If you are using ADFBC, the easiest way is to drop the attribute(Say Name) from the data control palette as outputText component and add partialTriggers property of it to point to table id(to refresh the outputText whenever the row is selected in table)
    Sireesha

  • How to get the values from html:select? tag..?

    i tried with this, but its not working...
    <html:select styleClass="text" name="querydefs" property="shortcut"
                 onchange="retrieveOptions()" styleId="firstBox" indexed="true">
    <html:options collection="advanced.choices" property="shortcut" labelProperty="label" />
    </html:select>
                        <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>

    <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>This java script is not working at all..its not printing anything in document.write();
    This is code..
    <td class="rowcolor1" width="20%">
    <html:select styleClass="text" name="querydefs" property="shortcut"
                             onchange="retrieveSecondOptions()" styleId="firstBox"
                             indexed="true">
                             <html:options collection="advanced.choices" property="shortcut"
                                  labelProperty="label"  />
                        </html:select>i tried with this also. but no use..i'm not the getting the seleced option...
    function retrieveOptions(){
    firstBox = document.getElementById('firstBox');
                             if(firstBox.selectedIndex==0){
          return;
        selectedOption = firstBox.options[firstBox.selectedIndex].value;
    }actually , how to get the values from <html:select> ...?
    my idea is to know which value is selected from the combo box(<html:select> ) if that value is equal some string i have enable a hyperlink to open a popup window

  • How to get background color of controls ?

    Hello everyone.
    How to get background color of controls ?
    When we use AWT/Swing,
    we can get background color of component by using Component.getBackground()
    It is regret that I can not find any method for such a method in JavaFX.
    And how do we detect the change of background color of controls ?
    Best regards.

    Hi Tadashi,
    try this.
    @Override
    public void start(final Stage primaryStage) {
        primaryStage.setTitle("Test ChangeListener");
        Button btn = new Button();
        btn.setText("change background");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                primaryStage.getScene().setFill(Color.rgb(
                        (int)(Math.random() * 255),
                        (int)(Math.random() * 255),
                        (int)(Math.random() * 255)));
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.getScene().fillProperty().addListener(new ChangeListener<Paint>() {
            @Override
            public void changed(ObservableValue<? extends Paint> arg0, Paint arg1, Paint arg2) {
                System.out.println(
                        "old color: " + arg1.toString()
                        + ", new color: " + arg2.toString());
        btn.getOnAction().handle(null);
        primaryStage.show();
    }Peter

  • How to get default values while using the transaction "BP"

    Hi Group,
    I have a query on how to get default values while using the transaction <b>BP</b>?
    The thing is:
    when I enter into the transaction "BP", I need to see some default values to some of the input fields in the screen.
    how can I achieve this?
    So please kindly let me know the procedure to achieve this.
    Thanks & Regards,
    Vishnu.

    Hi,
    The events of BDT can be used to default some fields on creating a partner.
    For this create a function module for ISDAT. attach that event in BUS7.
    In the ISDAT funtion modulethe following code should be used.
    For example to set the nationality:
    I_BUSDEFAULT-NATIO = 'DE.
    CALL FUNCTION 'BUP_BUPA_FIELDVALUES_SET'
    EXPORTING
    i_busdefault = I_BUSDEFAULT
    Regards, Smita.

  • How to get the path when i select a directory or a file in a JTree

    How to get the path when i select a directory or a file in a JTree

    import java.lang.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.HeadlessException;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Iterator;
    * @author Frederic FOURGEOT
    * @version 1.0
    public class JTreeFolder extends JPanel {
    protected DefaultMutableTreeNode racine;
    JTree tree;
    protected JScrollPane scrollpane;
    final static int MAX_LEVEL = 1; // niveau max de descente "direct" dans l'arborescence
    * Sous-classe FSNode
    * @author Frederic FOURGEOT
    * @version 1.0
    private class FSNode extends DefaultMutableTreeNode {
    File file; // contient le fichier li� au noeud
    * Constructeur non visible
    private FSNode() {
    super();
    * Constructeur par initialisation
    * @param userObject Object
    FSNode(Object userObject) {
    super(userObject);
    * Constructeur par initialisation
    * @param userObject Object
    * @param newFile File
    FSNode(Object userObject, File newFile) {
    super(userObject);
    file = newFile;
    * Definit le fichier lie au noeud
    * @param newFile File
    public void setFile(File newFile) {
    file = newFile;
    * Renvoi le fichier lie au noeud
    * @return File
    public File getFile() {
    return file;
    public JTree getJTree(){
         return tree ;
    * Constructeur
    * @throws HeadlessException
    public JTreeFolder() throws HeadlessException {
    File[] drive;
    tree = new JTree();
    // cr�ation du noeud sup�rieur
    racine = new DefaultMutableTreeNode("Poste de travail");
    // cr�ation d'un noeud pour chaque lecteur
    drive = File.listRoots();
    for (int i = 0 ; i < drive.length ; i++) {
    FSNode node = new FSNode(drive, drive[i]);
    addFolder(drive[i], node); // on descend dans l'arborescence du lecteur jusqu'� MAX_LEVEL
    racine.add(node);
    // Gestion d'evenement sur JTree (on �coute les evenements TreeExpansion)
    tree.addTreeExpansionListener(new TreeExpansionListener() {
    public void treeExpanded(TreeExpansionEvent e) {
    // lorsqu'un noeud est ouvert
    // on descend dans l'arborescence du noeud jusqu'� MAX_LEVEL
    TreePath path = e.getPath();
    FSNode node = (FSNode)path.getLastPathComponent();
    addFolder(node);
    ((DefaultTreeModel)tree.getModel()).reload(node); // on recharche uniquement le noeud
    public void treeCollapsed(TreeExpansionEvent e) {
    // lorsqu'un noeud est referm�
    //RIEN
    // alimentation du JTree
    DefaultTreeModel model = new DefaultTreeModel(racine);
    tree.setModel(model);
         setLayout(null);
    // ajout du JTree au formulaire
    tree.setBounds(0, 0, 240, 290);
    scrollpane = new JScrollPane(tree);
         add(scrollpane);
         scrollpane.setBounds(0, 0, 240, 290);
    * Recuperation des sous-elements d'un repertoire
    * @param driveOrDir
    * @param node
    public void addFolder(File driveOrDir, DefaultMutableTreeNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    addFolder(driveOrDir, node, 0);
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Recuperation des sous-elements d'un repertoire
    * (avec niveau pour r�cursivit� et arr�t sur MAX_LEVEL)
    * @param driveOrDir File
    * @param node DefaultMutableTreeNode
    * @param level int
    private void addFolder(File driveOrDir, DefaultMutableTreeNode node, int level) {
    File[] fileList;
    fileList = driveOrDir.listFiles();
    if (fileList != null) {
    sortFiles(fileList); // on tri les elements
    // on ne cherche pas plus loin que le niveau maximal d�finit
    if (level > MAX_LEVEL - 1) {return;}
    // pour chaque �l�ment
    try {
    for (int i = 0; i < fileList.length; i++) {
    // en fonction du type d'�l�ment
    if (fileList[i].isDirectory()) {
    // si c'est un r�pertoire on cr�� un nouveau noeud
    FSNode dir = new FSNode(fileList[i].getName(), fileList[i]);
    node.add(dir);
    // on recherche les �l�ments (r�cursivit�)
    addFolder(fileList[i], dir, ++level);
    if (fileList[i].isFile()) {
    // si c'est un fichier on ajoute l'�l�ment au noeud
    node.add(new FSNode(fileList[i].getName(), fileList[i]));
    catch (NullPointerException e) {
    // rien
    * Recuperation des sous-elements d'un noeud
    * @param node
    public void addFolder(FSNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    for (int i = 0 ; i < node.getChildCount() ; i++) {
    addFolder(((FSNode)node.getChildAt(i)).getFile(), (FSNode)node.getChildAt(i));
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Tri une liste de fichier
    * @param listFile
    public void sortFiles(File[] listFile) {
    triRapide(listFile, 0, listFile.length - 1);
    * QuickSort : Partition
    * @param listFile
    * @param deb
    * @param fin
    * @return
    private int partition(File[] listFile, int deb, int fin) {
    int compt = deb;
    File pivot = listFile[deb];
    int i = deb - 1;
    int j = fin + 1;
    while (true) {
    do {
    j--;
    } while (listFile[j].getName().compareToIgnoreCase(pivot.getName()) > 0);
    do {
    i++;
    } while (listFile[i].getName().compareToIgnoreCase(pivot.getName()) < 0);
    if (i < j) {
    echanger(listFile, i, j);
    } else {
    return j;
    * Tri rapide : quick sort
    * @param listFile
    * @param deb
    * @param fin
    private void triRapide(File[] listFile, int deb, int fin) {
    if (deb < fin) {
    int positionPivot = partition(listFile, deb, fin);
    triRapide(listFile, deb, positionPivot);
    triRapide(listFile, positionPivot + 1, fin);
    * QuickSort : echanger
    * @param listFile
    * @param posa
    * @param posb
    private void echanger(File[] listFile, int posa, int posb) {
    File tmpFile = listFile[posa];
    listFile[posa] = listFile[posb];
    listFile[posb] = tmpFile;

  • Can't get Lightroom Color Management to select custom profiles

    I can't get Lightroom Color Management to select custom profiles.
    - I select "other" in Profile,
    - a pop-up box shows me numerous profiles to choose from
    - I select a profile and the selection is highlighted
    - I press "OK" and the pop-up box disappears
    - but if I go back to the "Profile" selection line, only "Managed by Printer" is available.
    What's wrong here?
    Is the inability to select a profile the reason that prints from Lightroom look way to dark when I print them?
    Vick

    Oh, I'm on Windows, XP with SP2.
    The profiles are in C:\WINDOWS\system32\spool\drivers\color
    I used the .exe that was provided by Epson for installing the drivers.
    Nothing fancy, nothing different.
    For Lightroom, I installed it off CD, and got the 1.3.1 update off their Adobe site.
    Any clues there, to solve the puzzle?
    Vick

  • How do I change color in a selection, not globally?

    Hi guys,
    My question is how do I change color in a selection and not globally? My company uses Freehand currently and there is an option to find and replace color in a selection instead of the entire document. I need to figure out how to do this in Illustrator as we will be switching over shortly.
    Thanks,
    Ron

    Edit > Edit Colors > Recolor Artwork.

  • I use iPhoto and want to know how to get the 'key photo' i select on my MacBook Pro to be the one that gets used on my iPhone when i sync them. Any ideas? also, i want the events to appear in the order i choose on my MacBook too

    I use iPhoto and want to know how to get the 'key photo' i select on my McBook Pro to be the same one that gets used on my iPhone 5s when i sync. i also want the events to appear on the iPhone in the same order i have them on my macbook. any ideas there too?

    Killerfinch wrote:
    My new yahoo account nestles comfortably in iCloud on the mine iPad.
    No, your Yahoo account is not in iCloud (which only handles iCloud mail), it is in Yahoo, and the Yahoo mail account is on your iPad.
    But the MacBook Pro will have none of it! I write this question now as I fear that I will be totally demented very soon and unable to formulate my thoughts clearly!
    Get the correct settings for your account from Yahoo and set it up manually.
    By the way, I also find the "password" issue problematical. It seems Apple want my Apple password rather than my eMail password. All very confusing.
    That would depend on what you are trying to do.

  • HOW CAN I HAVE THE NUMBER OF SELECTED ROWS IN ALV GRID?

    HI.
    HOW CAN I HAVE THE NUMBER OF SELECTED ROWS IN ALV GRID????
    GABRY =)

    You need to use
    data : grid1  type ref to cl_gui_alv_grid.
      call method grid1->get_selected_rows
        importing
          et_index_rows = i_sel_alvrows[].

Maybe you are looking for

  • Nat inside to outside, IP not in same subnet as outside IP

    I already posted this but cant seem to find the post now, so re-posting. We have 10 IP's being NAT'd, all working ok.  I need a servers outbound source address to be translated to an IP that is not in the same subnet as the outside IP: Outside IP = 1

  • HOW do I delete the camera roll from my iPad2.

    I updated to ios7.02   I tried this Settings>General>Usage>Storage>Photos and Camera.     and you can't swipe and get a delete option..  how do I delete the camera roll? I don't want to have to delete each of the 900 photos one at a time.  

  • Value for customized fields didn't get copied to back end system

    Hi, We are in SRM 4.0 and using extended classic scenario. We have defined two customized fields in account assignment tab in shopping cart and SRM Po and also in back end PO. SRM POs are having values for the field but while transferring the Po deta

  • Collapsible panel not working

    Hi, I am facing a problem with Collapsible panel provided by tomahawk. The action method of the command link in the <f:facet> is not invoked.* This method is used for toggling the value of the boolean variable assigned to value attribute of <t:collap

  • My photos aren't in the iphoto library

    I clicked on my photo library to see my pictures and they were all missing. I'm not sure how that happened and how to recover what happened. Any ideas?