Incorrect list item background color in Nimbus custom ListCellRenderer

Hi there,
I've been doing lots of web searches trying to come up with what's going on here. It seems other people have had the same problem I've had, but in the one place that seems to nail the question directly, it doesn't seem to be resolved. The issue is that I'm using a JPanel as a ListCellRenderer for a JList. I'm using the Nimbus LAF, and my problem is that the background of the panel doesn't seem to have its background color set properly. I call setBackground on it, and it should be setting it to a DerivedColor that's pure white, but it seems to have no effect. Manually calling setBackground to white works, but it also means I've now hardcoded the color into it, which I'm trying to refrain from doing. Here's some code to reproduce the issue:
import java.awt.Component;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.Border;
public class ListTest extends JFrame {
  private JScrollPane scrollPane = new JScrollPane();
  private JList list = new JList(new String[] {"TEST 1", "TEST 2"});
  private class Renderer extends JPanel implements ListCellRenderer {
    private JLabel text = new JLabel();
    public Renderer() {
      add(text);
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      setEnabled(list.isEnabled());
      Border border = null;
      if (cellHasFocus) {
        if (isSelected) {
          border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
        if (border == null) {
          border = UIManager.getBorder("List.focusCellHighlightBorder");
      } else {
        border = UIManager.getBorder("List.cellNoFocusBorder");
      setBorder(border);
      // set renderer values
      text.setText((String)value);
      text.setFont(list.getFont());
      if (isSelected) {
        setBackground(list.getSelectionBackground());
        text.setForeground(list.getSelectionForeground());
      } else {
        // the color returned from list.getBackground() is pure white
        // but the list items appear with a grey background!
        setBackground(list.getBackground());
        // THIS works -- but is obviously hardcoded
        // setBackground(Color.WHITE);
        text.setForeground(list.getForeground());
      return this;
  public ListTest() {
    list.setCellRenderer(new Renderer());
    scrollPane.setViewportView(list);
    add(scrollPane);
    pack();
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
          if ("Nimbus".equals(info.getName())) {
            try {
              UIManager.setLookAndFeel(info.getClassName());
            } catch (Exception ex) { }
        new ListTest().setVisible(true);
}Here's a StackOverflow question that is exactly what I'm experiencing, but doesn't seem to be exactly resolved: http://stackoverflow.com/questions/2787781
Any ideas would be greatly appreciated!
Thanks!

// the color returned from list.getBackground() is pure white
// but the list items appear with a grey background!
setBackground(list.getBackground());
// THIS works -- but is obviously hardcoded
// setBackground(Color.WHITE);So when you hardcode the background you are using a Color object.
Have you added any debug info to see what kind of class list.getBackground() returns?
If it is some fancy class that extend Color, you can always create your Color object by using:
Color background = new Color(....)
Then all you have to do is get the RGB values from the list Color object.

Similar Messages

  • Change item background color on runtime

    Hello
    i have a List control in my application. What do I have to do
    to change its items background color on runtime?
    Thanks

    You have to access the style of the object and then set the
    piece of the style you want to change. You need to set
    backgroundColor.
    myList.setStyle("backgroundColor", "#ABABAB");
    #ABABAB is grey, and you can put any hex color value there
    you like.
    Hope that helps.

  • Item Background Color changes when placed in production (Forms 10g)

    Hello All,
    I have searched the forum on this topic, but have not been successful in finding a topic/solution for multi-line items that need to render a different color than the rest.
    I have used set_item_instance_property (and set_item_property) as well as using a VA to resolve this issue to no avail.
    When I view the form in the browser - initially in query-mode, I see the color that I have set for the item. Once the query is fetched and I am in non-query mode (display), the items background color is replaced to the standard color (off yellow) for non-editable fields.
    I have taken all of the subclasses off, used the item property from the pallette as well as manually programmed within a trigger and cannot get this item to stay the color that I have set.
    Can anyone help me get this working?

    Are you using the 0 to 100 rgb color assignments you see in the Forms Builder color palette? If so, that is your problem. At run time, you have to convert the color numbers to 0 to 255 numbers. Just multiply each of the three parts by 2.55
    Or maybe there is come code running elsewhere in your form that is setting the color after your code is run.
    Search your form for background_color.

  • Selection background color in a custom TreeCellRenderer

    I'm trying to write a custom TreeCellRender and I'm not having any luck getting the selection to work. When I click on a node (leaf or not) the color of the node does not change. If I use the default renderer instead of my custom renderer selection works fine. I've tried everything I can find on the web, setOpaque(true) setTextSelectionColor() etc but I'm not getting anywhere. I've also tried setting the background color in getTreeCellRendererComponent() based on the selected boolean. Still nothing.
    Here's my code:
    class PackageTreeRenderer extends DefaultTreeCellRenderer {
         public PackageTreeRenderer() {
              setOpaque(true);
              setTextSelectionColor(getBackgroundSelectionColor());
         public Component getTreeCellRendererComponent(JTree t,Object value,boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              Object obj = node.getUserObject();
              if(obj instanceof String) {
                   String name = (String) obj;
                   setText(name);
              if(obj instanceof ResultPackageInterface) {
                   ResultPackageInterface rpi = (ResultPackageInterface) obj;
                   String name = "Name";
                   try {
                        name = rpi.getDescription();
                   catch(RemoteException ex) {
                        errorMessage(ex);
                   setText(name);
              if(leaf) {
                   setIcon(getLeafIcon());
              else {
                   if(expanded) {
                        setIcon(getOpenIcon());
                   else {
                        setIcon(getClosedIcon());
              return this;
    }Hope someone can help.

    Thanks for the suggestions everyone but I got it working. Instead of extending DefaultTreeCellRenderer it works if I extend JLabel and implement TreeCellRenderer. Here's my code for future reference:
    class PackageTreeRenderer extends JLabel implements TreeCellRenderer {
         public PackageTreeRenderer() {
              setOpaque(true);
         public Component getTreeCellRendererComponent(JTree t,Object value,boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              Object obj = node.getUserObject();
              setText(obj.toString());
              if(obj instanceof String) {
                   String name = (String) obj;
                   setText(name);
              if(obj instanceof ResultPackageInterface) {
                   ResultPackageInterface rpi = (ResultPackageInterface) obj;
                   String name = "Name";
                   try {
                        name = rpi.getDescription();
                   catch(RemoteException ex) {
                        errorMessage(ex);
                   setText(name);
              if(leaf) {
                   setIcon(UIManager.getIcon("Tree.leafIcon"));
              else {
              if(expanded) {
                   setIcon(UIManager.getIcon("Tree.openIcon"));
              else {
                   setIcon(UIManager.getIcon("Tree.closedIcon"));
              if(sel) {
                   setForeground(UIManager.getColor("Tree.selectionForeground"));
                   setBackground(UIManager.getColor("Tree.selectionBackground"));
              else {
                   setForeground(UIManager.getColor("Tree.textForeground"));
                   setBackground(UIManager.getColor("Tree.textBackground"));
              return this;
    }

  • How to change the current item background color

    I m working in forms 6.0.
    I want to mak the background color of the current item (whatsoever the item name is ) as 'yellow'. How can i do that.How can i accoplish that? I've tried
    set_item_property(:system.cursor_item,background_color,'yellow');
    in Pre_text_item
    set_item_property(:system.cursor_item,background_color,'white');
    in post_item_item
    at block level
    But i failed to do that
    anyone to help me plz
    Riaz Shahid

    hi riaz,
    i think instead of pre-text-item put the code in when new item instance.or try creating a visual attribute with background color as yellow and attach that using set_item_property in when new item instance or check for help on DISPLAY_ITEM built in in forms help.I think one of these should definitely help u.
    bye
    Atul

  • Changing only 1 menu item background color in a VerticleSpryMenu

    Im working on this Verticle Spry Menu Bar (seen below) . I'm trying to figure out how to change the 'Get Started!' Item to be a different color than orange.  Home, Support and Get Started!  are clickable links with no submenu whereas the other menu items have submenus. Is there a special code to customize just Get Started!. Through CSS stylesheet I can get Get Started to change color  but then Home and Support also change color and I dont want that.
    Thanks

    For all menu items use the following selectors
    ul.MenuBarVertical a
    ul.MenuBarVertical a:hover, ul.MenuBarVertical a:focus
    ul.MenuBarVertical a.MenuBarItemHover, ul.MenuBarVertical a.MenuBarItemSubmenuHover, ul.MenuBarVertical a.MenuBarSubmenuVisible
    For menu items with sub menu items use the following selectors to override the above
    ul.MenuBarVertical a.MenuBarItemSubmenu
    ul.MenuBarVertical a.MenuBarItemSubmenuHover
    Gramps

  • Current item Background Color

    Hello Friends,
    I am facing some problem in changing the bachgroud color of the selected field in block,
    Basically i want to make visible the current field in a record,not the enire record but just the current item.
    thanks to all;

    Create WNII and POST-TEXT-ITEM triggers (block level) with command
    Set_Item_Instance_Property(:SYSTEM.CURRENT_ITEM, CURRENT_RECORD, VISUAL_ATTRIBUTE, <VA_NAME>);
    Note! Current record VISUAL ATTRIBUTE of block must be <NULL>.

  • List items do not refresh correctly.

    In a form that i have developed there are two list items. I
    want among others to chenge their appearance (background color
    basicaly) according to witch one has th focus each time.
    So I've put this code on the items, in WHEN-NEW-ITEM-INSTANCE
    triger:
    * LIST1
    SET_ITEM_PROPERTY('LIST1',VISUAL_ATTRIBUTE,'SELECTED');
    SET_ITEM_PROPERTY('LIST2',VISUAL_ATTRIBUTE,'GREYED');
    * LIST2
    SET_ITEM_PROPERTY('LIST2',VISUAL_ATTRIBUTE,'SELECTED');
    SET_ITEM_PROPERTY('LIST1',VISUAL_ATTRIBUTE,'GREYED');
    The Visual Attributes have the colors that i would like to
    appear on the items.
    This does not work (while it was working on Forms 5.0). It
    seems to be a refresh problem, because when you open another
    form that covers this one, or you minimize and maximize it the
    colors are assigned corectly.
    Thanks in advance for your help.
    null

    Panagiotis Lygnos (guest) wrote:
    : In a form that i have developed there are two list items. I
    : want among others to chenge their appearance (background color
    : basicaly) according to witch one has th focus each time.
    : So I've put this code on the items, in WHEN-NEW-ITEM-
    INSTANCE
    : triger:
    : * LIST1
    : SET_ITEM_PROPERTY('LIST1',VISUAL_ATTRIBUTE,'SELECTED');
    : SET_ITEM_PROPERTY('LIST2',VISUAL_ATTRIBUTE,'GREYED');
    : * LIST2
    : SET_ITEM_PROPERTY('LIST2',VISUAL_ATTRIBUTE,'SELECTED');
    : SET_ITEM_PROPERTY('LIST1',VISUAL_ATTRIBUTE,'GREYED');
    : The Visual Attributes have the colors that i would like to
    : appear on the items.
    : This does not work (while it was working on Forms 5.0). It
    : seems to be a refresh problem, because when you open another
    : form that covers this one, or you minimize and maximize it the
    : colors are assigned corectly.
    : Thanks in advance for your help.
    Hi Panagiotis Lygnos ,
    I am not able to produce this problem. I create one form with
    two list item ,two visual attribute & when-new-item-instance
    trigger for these two list item as you have written above.
    But List item background color of both list item is getting
    changed according to witch one has th focus each time.
    Even I tried to call this form from some other form still I am
    getting correct result.
    Can you just try by adding synchronize in the trigger of
    both list item.
    SET_ITEM_PROPERTY('LIST1',VISUAL_ATTRIBUTE,'SELECTED');
    SET_ITEM_PROPERTY('LIST2',VISUAL_ATTRIBUTE,'GREYED');
    Synchronize;
    Bye
    Mani/-
    null

  • Select list based on color

    Hi there
    I need to create a static select list in a tabular form with the following values: Red, Amber, Green.
    However, instead of the color names, the user wants to see the actual colors in the the select list (changing background color for each option), so it is easy to spot the problematic ones (Red). Is this possible to be done using Apex 3?
    Thanks
    Luis

    Luis et al.
    Thanks for posting code to this forum, it has been a great help. I must admit that I know nothing about javascript (close enough to nothing) but through the great posts here I have been able to get the first part working and my list values change color when the page loads. However, when I use the select list I don't know how to implement the code Luis posted to change the background color in the select lists. Any further direction would be a great help.
    I have the example page here:
    http://apex.oracle.com/pls/otn/f?p=37008:18
    and this is the code I used so far in the HTML HEADER on the page:
    <script type="text/javascript">
    function setAll()
    obj=document.forms[0];
    len=obj.elements.length;
    for (i=0;i<len;i++){
    if (obj.elements.name=="f04")
    setColor(obj.elements[i]); }
    function setColor(sel)
    var obj=sel;
    if (obj.value=='GREEN')
    obj.style.backgroundColor= "green";
    if (obj.value=='YELLOW')
    obj.style.backgroundColor= "yellow";
    if (obj.value=='RED')
    obj.style.backgroundColor= "red";
    if (obj.value=='WHITE')
    obj.style.backgroundColor= "white";
    </script>
    Thanks again,
    Dave

  • How to pick up value from list item

    I created one form with list item(used to display all customer name).
    From this i want to select one customer name and stored in a variable.. how can i do this..

    Use the Get_List_Element_Value function e.g.:
    declare
         v_customer_name VARCHAR2(50);
    Begin
         v_customer_name:= Get_List_Element_Value('customer_list', 1);
    End;

  • Background color unbound list item on web

    We've got an unbound list item, which background color is changed dependent on it status (required or not). This all works fine in client/server, but on the webserver we only get a gray list.
    Has anyone a clue?

    What version of SharePoint are you using?  You mention a newer version of SharePoint but posted in the legacy forums so I'm not sure.  I'm going to take a stab that you're using SPD 2013 without the Design review.
    For your specific task, you'd really need to use Developer tools to isolate the css class.  CSS within SharePoint is a tricky beast.  If you're using Publishing sites or have activated the publishing features, then typically you'd use the system
    created Styles folder to override CSS locally.
    It's a little hard to be more precise without knowing exactly which scrollbars you want to change.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Background color of a list item implemented as Tlist

    Hi,
    I have one form with 3 blocks each holding one list item. The list item that has the focus should have a different background color from the other 2 list items. I thought to implement this with visual attributes I assign in the when-new-block-instance trigger. This however only partially works.
    What happens is the following :
    At startup focus is in the first block. This block's when-new-block-instance trigger is fired :
    SET_ITEM_PROPERTY('BK_LIST.LIST',VISUAL_ATTRIBUTE ,'VA_INDICATOR');
    SET_ITEM_PROPERTY('BK_LIST2.LIST',VISUAL_ATTRIBUTE ,'VA_ENABLED_LIST');
    SET_ITEM_PROPERTY('BK_LIST3.LIST',VISUAL_ATTRIBUTE ,'VA_ENABLED_LIST2');
    and the list correctly gets it's yellow background. (defined in va_indicator)
    Va_enabled_list and va_enabled_list2 both have a white background, difference between them is the font size)
    Now when we move focus to the 2nd block we get a different behaviour. This is the trigger defined on the 2nd block :
    SET_ITEM_PROPERTY('BK_LIST.LIST',VISUAL_ATTRIBUTE ,'VA_ENABLED_LIST');
    SET_ITEM_PROPERTY('BK_LIST2.LIST',VISUAL_ATTRIBUTE ,'VA_INDICATOR');
    SET_ITEM_PROPERTY('BK_LIST3.LIST',VISUAL_ATTRIBUTE ,'VA_ENABLED_LIST2');
    So I except the first block to get a white background again and the second block to get it's yellow background. However only the selected row in the tlist changes it's background color. (this in both blocks)
    I do not understand why the first time (at form startup) the background color is set for the whole item and the second time only for the selected record.
    I tried to use the property background_color but the colors are different from what I see in my color palette in that case. If I use the same color codes I also use in my visual_attributes the final result on the screen is different...
    Secondly the result is the same, at form startup the item's background is set, as from the second call only the current salected record in the tlist will change from background color.
    Forms are running C/S and are developed in Forms 6i. One way to get the result I need is by navigating back & forward to my application in Windows using Alt-Tab. At that moment the correct background colors are suddenly applied... Is there a way to force a similar sort of screen refresh ?
    Thanks for any hints, workarounds, tips or solutions !
    Kris
    Message was edited by:
    [email protected]

    Hi,
    I still don't have a clue how I could solve this one.
    It works leaving the block (so making it white again) but it does not work entering the block. (giving the list item another background color). The problem is not about the whithe color. If I do my tests with other colors (red-yellow) the problem remains.
    Best Regards,
    Kris

  • How can I create an alt background color for items in a jlistbox or jtree

    What I'm looking to do is have a white background for say items 1,3,5, etc. and a light yellow background for items 2,4,6, etc. I was wondering how can I set an alternative background color on items in a JTree or a JList

    Use a cell renderer:
    import java.awt.*;
    import javax.swing.*;
    public class ListAlternating extends JFrame
         public ListAlternating()
              String[] items = {"one", "two", "three", "four", "five", "six", "seven"};
              JList list = new JList( items );
              list.setVisibleRowCount(5);
              list.setCellRenderer( new MyCellRenderer() );
              JScrollPane scrollPane = new JScrollPane( list );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              ListAlternating frame = new ListAlternating();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
         class MyCellRenderer extends DefaultListCellRenderer
              public Component getListCellRendererComponent(
                   JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
                   super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                   if (!isSelected)
                        setBackground(index % 2 == 0 ? list.getBackground() : Color.LIGHT_GRAY);
                   return this;
    }

  • How to resize and change background color of table item

    i am using netbeans as a compiler and i am using an item (in my mobile application)called org.netbeans.microedition.lcdui.TableItem.Can i change row height and column
    width.Also i wanna change cell background color.How can i do these?
    THX FOR REPLIES

    http://www.netbeans.org/kb/50/custom-tableitem.html

  • How do I keep a previously list item colored?

    When I visited a web site that had a list of items to select, the selected item was colored. That prevented me from duplicating previous selections. I have lost this feature. How do I get it back?
    Thanks
    Frank G C
    FF 3.6.13
    Win Vista Ultimate SP2

    Sorry, but once they're in the download queue, you can't remove them yourself. Contact the iTunes Store customer support department through the form linked from the bottom of their Download FAQ web page and explain the problem to them. They may be willing to remove the items from your queue for you.
    Regards.

Maybe you are looking for