Point wrong list in Nimbus ListCellRenderer custom background color

Hello

I did a lot of research on the web being lead to what happens here. It seems that other people have had the same problem that I had, but in the only place that seems to nail the issue directly, it seems not be solved. The problem is that I use a JPanel as a ListCellRenderer for a JList. I use Nimbus Lebanese armed forces, and my problem is that the background of the Panel does not seem to have its background color set correctly. I call setBackground on it and it should be the establishment of a DerivedColor which is pure white, but he seems to have no effect. Manually dialing the white setBackground works, but it also means I've now hardcoded color in it, I'm currently doing. Here's some code to reproduce the problem:
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 is exactly what I saw, but does not seem to be solved exactly: http://stackoverflow.com/questions/2787781

Any ideas would be greatly appreciated!

Thank you!
// 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);

Then when hard-code you the background you use a Color object.

Did you add debug information to see what type of class list.getBackground () return?

If it is a class of fancy which range from color, you can always create your color object using:

Background color = new Color (...)

All you have to do is get the RGB values of the color list object.

Tags: Java

Similar Questions

  • Substitute CellRenderer of the list but keep the default background color

    I set up a custom CellRenderer class to apply a different font when rendering a list. But the default background color disappeared as well. It was a pure white when the custom CellRenderer class was created.

    How could I apply the custom font for a list, but keeping the default background of display (dark and light gray on the lines of even / odd)?

    Thank you very much for your help!

    Implemented as a cellrenderer alternation. Then simply change the font.

  • jQuery to update the background color select list

    I have this element in a tabular presentation.

    < select name = "f15" id = "f30" autocomplete = "off" >

    < option value = "" selected = "selected" > < / option > "

    ROSE < option value = "PINK" > < / option >

    < option value = "SILVER" > SILVER < / option >

    < / select >

    I try to use jQuery to f30 in the table, then for each item in this table cross list items and set the background color for what is in the value field.

    But I can't even the value of each item in the selection list. This.Value and $(this) .val () return null.

    This is my small effort:

    $("[name="f15"]').each (function () {}

    line = apex.jQuery (this) .closest ('tr');

    Alert ('value =' + This.value);

    Alert ('value =' + $(this).) Val());

    . style.backgroundColor $(this) = this.value;

    $(this) .css ({backgroundColor: this.value});

    $(this) .css ("background-color", "red");

    });

    Hello

    $("#f30>option").each(function() {
      console.log(this.value);
    });
    
  • Exchange of dynamic region background color

    I've seen a few posts about this, but they do not work for me. I'm changing the background color of a form region that is based on the value of an element from the selection list.

    I have 2 regions on a page

    The first region is the item selection list.

    The second region is based on a table.

    What value is depending on the selection in the first region list item, I want the background color to change to the second region.

    For example: If the select list item is 'A' then I want the second region to have a red background color

    If the select list item is 'B', then, I want the second area to have a yellow background color

    If the select list item is 'C' then I want the second area to have a blue background color

    Thank you

    Ashok

    And one more thing:

    Change the line in swesley_perth :

    $('p42_region').css('background-color',colour);
    

    By (including the #):

    $('#p42_region').css('background-color',colour);
    

    It will work.

  • change the background color of the interactive reports

    Hi all

    I'm trying to change the background color of the interactive report. Is there anyway where I could change the background color of report? My all other reports are using custom background color, but in the case of report interactive, I couldn't manage change its default background color.

    Thank you
    Manish

    Hello

    Sorry, you said custom background color, so I thought you had that. The color I put here is just white, so you may have to adjust to match your custom color

    Probably the easiest way is to create an HTML region without a model to 0 in the position after the page header. Can use it as the source of the region

    
    

    You can also put in the page template or an external CSS file.

    If your has begun on CSS I suggest that you spend an hour or two reading this site [http://www.w3schools.com/css/], it will save you hours more later any web development environment you use

    Kind regards
    Carl

  • given that I installed the latest version of Firefox my homepage to Google won't keep my custom background. Everyone knows about this problem?

    I always use Google as my home page and custom background with one of my own photos. Since I installed the latest update of Firefox my homepage to Google watch my picture for a brief second and then merely white. I changed it several times in my photo, but it will not stick. It looks like others using Google as their home page have the same problem, but nobody got fixed I can see about using Google positions. Someone related to the problem of Firefox.

    You can post the details on how fixed and that caused it?

    It helps people who have read this thread.

  • custom background does not

    I used different background images on my signs for years. Never had a problem until now. Now, they seem to not work. No custom backgrounds, not even work the supplied LV (steel, wood, clouds, etc.) ones. I can see them in the browser, but they will not go to the background of the front panel. Win 7 and LV2012. Someone at - it is possible to duplicate this behavior?

    It is perhaps not very convenient, but you can try this to test the system.

    https://decibel.NI.com/content/docs/doc-5882

  • SPA962 commissioning custom background

    Nobody knows what are the XML settings to provide a custom background of BMP on a SPA962? My firmware is 5.1.5. I can make it work from the web interface, but could not find the appropriate configuration settings. Thank you.

    Here's the XML to the URL:

    Insert the URL here

  • Background color of the custom field

    Hello

    I create a custom field that is as shown in the attached display a bar graph.

    I don't want to change the background color of the field of another color. I tried to overridding method paintBackground of the field as shown below:

    protected void paintBackground(Graphics arg0) {
            arg0.setColor(Color.DARKGRAY);
            super.paintBackground(arg0);
        }
    

    but it seems to have no effect. Could someone kindly help me with this. Thanks in advance.

    Kind regards

    S.A.Norton Stanley

    Try this...

    Create a class that extends the scope and implements DrawStyle

    and override its Paint method... to set the background color

    Draw the shape you want with the graphics object and either fill the area or set the background color.

    THX

    Rabi Ray

  • Customizing the background color for an element ListField

    I spent the better half of today trying to figure out how to set the background color for when a ListField element has the focus. I tried the substitution of paint and drowFocus and can not get any color other than the default.

    Someone knows how to do this?

    Try something like that.

     public void drawListRow(ListField list, Graphics g, int index, int y, int w)
    {
        if(list.getSelectedIndex() == index)
        {
             g.setColor(0x0000FF);
             g.fillRect(0,(index*rowHight),rowWidth,rowHeight);
             g.setColor(0x000000);
        }
        g.drawText("Text", 0, y, 0, w);
    }
    

    PS: Call disabled, if the previous paint stays on the screen.

  • a badge of the value-based list background color

    Hello

    I am using Apex5 on Oracle 11 g. I'm playing the plugin list Badge to come with Apex packaged Application, I would like to know if it is possible to change the background color (fill color) of the badge round based on the range of values, for example, I'm working on a few badge tickets report, I am critical, high, medium, low budget, what I want is that the values is 0 (no tickets) and then display the badge as green Cycle; If 1-10, show orange. If greater than 10, shows red.

    Thank you

    Mike

    I thought about it. Here's what I did:

    Create a refreshment after DA (java script based) and java scripts:

    $(".t-BadgeList-value").each (function () {}

    If (parseInt ($(this) .text ()))<>

    $(this).css({"background-color":"green"});)

    on the other

    $(this).css({"background-color":"red"});)

    });

    Thank you

  • Change the background color of a table cell, depending on the selection in a drop-down list

    I have a drop-down list wrapped in a subform in a table cell. Users can choose green, yellow or red, and I want the background color to change according to their choice.

    Can you tell me why this script does not work? I'm sure that some of you, dear friends can see in a second.


    If (this. ListItem == "green") {}

    Subform1.DropDownList1.fillColor = "000,128,000"; BackgroundFill = "solid";

    }

    If (this. ListItem == 'yellow') {}

    Subform1.DropDownList1.fillColor = "255,128,000";

    }

    If (this. ListItem == 'red') {}

    Subform1.DropDownList1.fillColor = "255,000,000;

    }


    Thank you

    Hello

    I think you should be able to use the following code in the event change of the dropdownlist control.

    Form1. #subform [0]. Table1.row2.DropDownList1::change - (JavaScript, client)

    If {(xfa.event.change=="green)"}

    this.fillColor = "000,128,000";

    }

    If {(xfa.event.change=="yellow)"}

    this.fillColor = "255,128,000";

    }

    If {(xfa.event.change=="red)"}

    this.fillColor = "255,000,000;

    }

    Concerning

    Bruce

  • list drop down background color of paper list

    I have a form with fields about 500.  The drop-down list fields (20 of them) all print with a blue background, dark, even with the properties defined on any background color.  None of the other fields print with a background color. No idea how I can eliminate this boring action in Acrobat Pro XI?

    Yes, the color you see is selected items in a list box. It can not

    be changed. Just change them to a drop-down list field to get rid of him.

  • Custom background gradient for ToolTip color

    Hello

    I created a custom ToolTip where I use light gray background color.

    (I created a separate custom tooltip component.)

    Now user wants her to be with a gradient effect (is that his name?).

    Basically, this gray color should be darker in the region at the top of the ToolTip page.

    This color goes progressively lighter from top to bottom.

    Can you tell me how this can be done?

    Thank you and best regards,
    Amey

    Hello.

    Sorry, my mistake - I guess you use flex 4.

    This message tells you how to add a gradient to a background of vbox: ers http://butterfliesandbugs.wordpress.com/2007/06/08/generic-background-gradient-for-contain /

  • background color for the disabled change point

    Hello!

    I disabled an element. The background color of this item is gray (default).
    Value of the attributes of the Form HTML of the text element element is disabled.
    I would like to change to another color.
    How can I do? I don't want to use javascript...

    THX,

    Add the following code to the attributes of the element of the form element

    style="background-color:yellow;"
    

    Adjust the specification of the color according to your needs.

    CITY

Maybe you are looking for

  • Problems of HDCP on iMac nine 5 k

    Hi Im getting an error message on my new iMac Impossible to watch this movie because its on a screen that is not allowed to play protected movies try to move this window to a different display or disconnect any display that is not authorized HDCP The

  • Get horizontal wrinkles when scrolling down in the active window in firefox.

    Using the latest version of Firefox on a Dell XPS 630i, Win 7 Pro. Use of a HP w2338h monitor set in 1620 x 1050 at 60 Hz. Graphics card is NVIDIA GeForce GTS 240. Logitech Anywhere Mouse MX. When scrolling down I get lines on the screen when I type

  • How to turn on the screen of the Satellite series laptops

    Accedently, I made a bad combination of Fn keys and now my screen upside down (turned 180 degrees).How can I reset it?

  • How to install the tcp/ip

    I'm trying to connect to the Internet, but I had this "failed to query the connecton tcp/ip parameters" somebady can helpme please

  • Photo record to the flash drive

    How to save pictures to my Gallery of photos to a flash drive?  I did once and now don't remember how.  No matter what I choose, choose to copy, or click right on, I can't understand it.