Changing the disabled foreground color of a disabled JList

I am using a JList inside JScrollPane. If the list is disabled the foreground color of list changes to grey. How can I change this disabled foreground color.
regards,
nirvan.

Well, a JList uses a JLabel as the default renderer. So you can try using the UIManager to set the "Label.disabledForeground" color to whatever you want. Of course this will also affect disabled labels.
Or, you can create a custom renderer for the list and control the disabled color in the renderer.

Similar Messages

  • Can I change the back/foreground color of a disabled JComboBox?

    I need to change the color of the text or the background for a disabled JComboBox. My users would like to be able to see the data better even though they can't alter it.

    I see i have to create a ComboBoxUI, but have no idea how to start a simple one.Then start with an existing one.
    a) look at the source code for BasicComboBoxUI
    b) find the occurences of 'disabledBackground' and 'disabledForeground' to give you an idea of where to make your changes and then override those methods
    Thats the easy part. If you run this [url http://www.discoverteenergy.com/files/ShowUIDefaults.java]program you will notice that the Metal LAF uses the      javax.swing.plaf.metal.MetalComboBoxUI class and the Windows LAF uses the com.sun.java.swing.plaf.windows.WindowsComboBoxUI class. So if you need to support both LAFs then you would need to override both classes and tell the LAF Manager which class to use. I don't know how to do this.

  • Foreground color of a disabled component

    How do i change foreground/text color of a disabled component? Something similar to JTextComponent's setDisabledTextColor().

    I'm not exactly sure but I think this is highly component dependent and even look & feel dependent. Sometimes, there isn't even a such color defined anywhere. The component's ui just takes the current foreground color and calls brighter on it.
    You'll have to be more specific on the component you wish to modify.

  • Foreground Color of a Disabled AWT Component

    How do you change the foreground color of a disabled AWT component?

    You would have to write your own renderer that checkes to see if the component is enabled or disabled. Your renderer would then draw the component as you like in both of those states.

  • Disabled foreground color in JComboBox

    what's the correct way to set the disabled foreground color of a jcombobox? i don't want to set the disabled color for the entire ui to the same color, but for one jcombobox specifically. i searched the web and found many posts with the same question, but no real solution. this one has been giving me nightmares and i thought i'd share what i've found. the solution seems to be quite simple: wrap the combobox label in a panel. that way the panel gets the disabled colors, but the coloring of the label of the combobox remains. here's the solution in short in case others need it:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.ListCellRenderer;
    public class MyComboBox extends JComboBox {
      public MyComboBox() {
        super();
        setRenderer( new ColorCellRenderer());
      public static void main(String s[]) {
        JFrame frame = new JFrame("ComboBox Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final JComboBox cb = new MyComboBox();
        cb.addItem( "ComboBox Item 1");
        cb.addItem( "ComboBox Item 2");
        cb.addItem( "ComboBox Item 3");
        cb.setForeground( Color.blue);
        final JButton bt = new JButton ("disable");
        bt.addActionListener( new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            cb.setEnabled( !cb.isEnabled());
            if( !cb.isEnabled()) {
              cb.setForeground( Color.red);
              bt.setText( "enable");
            } else {
              cb.setForeground( Color.blue);
              bt.setText( "disable");
        frame.getContentPane().setLayout( new FlowLayout());
        frame.getContentPane().add( bt);
        frame.getContentPane().add( cb);
        frame.pack();
        frame.setVisible(true);
      class ColorCellRenderer implements ListCellRenderer {
        protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
        public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
          JLabel label = (JLabel) defaultRenderer
              .getListCellRendererComponent(list, value, index,
                  isSelected, cellHasFocus);
          JPanel wrapper = new JPanel();
          wrapper.setLayout( new BorderLayout());
          wrapper.add( label, BorderLayout.CENTER);
          return wrapper;
    }if anyone knows a way to remove the dropdown button of a disabled combobox without leaving a blank space when you simply hide the button, feel free to extend this :-)
    Edited by: Lofi on Mar 20, 2010 10:46 PM

    i thought i'd share what i've found. the solution seems to be quite simple: wrap the combobox label in a panel.Brilliant! I'm sure this will be useful to others who find this solution here.
    Your code does have some unnecessary overheads though, like constructing a new JPanel in every call to getListCellRendererComponent, and holding a separate renderer as a field. I've attempted to clean it up for brevity and efficiency.import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JCheckBox;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class DisabledForegroundListCellRenderer extends DefaultListCellRenderer {
      private final JPanel wrapper = new JPanel(new BorderLayout());
      public DisabledForegroundListCellRenderer() {
        wrapper.add(this);
      @Override
      public Component getListCellRendererComponent(JList list, Object value,
              int index, boolean isSelected, boolean cellHasFocus) {
        super.getListCellRendererComponent(list, value,
                index, isSelected, cellHasFocus);
        return wrapper;
      // Test rig
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            new DisabledForegroundListCellRenderer().makeUI();
      public void makeUI() {
        String[] data = {"One", "Two", "Three"};
        final JComboBox combo = new JComboBox(data);
        combo.setRenderer(new DisabledForegroundListCellRenderer());
        final JCheckBox check = new JCheckBox("Combo enabled");
        check.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            boolean selected = check.isSelected();
            combo.setForeground(selected ? Color.BLUE : Color.RED);
            combo.setEnabled(selected);
        check.doClick();
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.add(check, BorderLayout.NORTH);
        frame.add(combo, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }I've also changed the class name, as to me "ColorCellRenderer" would rather imply something that renders either the foreground or the background (or both) on the basis of the value parameter.
    if anyone knows a way to remove the dropdown button of a disabled combobox without leaving a blank space when you simply hide the buttonThat would require a custom UI delegate, not a custom renderer. And really, I wouldn't bother -- I would just use a JComboBox and a disabled (or maybe uneditable) JTextField, held in a CardLayout, and swap them instead of disabling the combo.
    Shall take a look at how the combo UIs reserve space for the button though :)
    luck, db
    Edited by: DarrylBurke -- changed wrapper to private final, it shouldn't be static

  • How to set disabled foreground color of JCheckBox?

    How do I set the disabled foreground color of JCheckBox? To clarify, I want to choose the color that is used to paint the component's foreground when it is disabled.
    thanks.

    Check out this thread:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=122112

  • My Apple ID has been disabled. I changed the password, but I'm still disabled. Help!

    My Apple ID has been disabled. I have changed the password, but I'm still disabled. I cannot buy music, apps, etc. I have hundreds invested in my library and the "support" page for Apple ID is getting me nowhere. Help!

    Click Support at the top if this page, then click the link under Contact Us.

  • TS2446 my apple id has been disabled, i have changed the password but it is still disabled

    my apple id has been disabled, i have changed the password but it is still disabled.
    can you please tell me what to do

    Go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store.
    Regards.

  • How can I change the font and color of an email signature?

    How can i change the font and color of an email signature?

    Mail > Preferences > Signature
    Highlight the Signature.
    Click Format in the menu bar and select " Show Fonts".
    Select the Font.
    Highlight the Text.
    Click Format in the menu bar and select " Show Colors".
    Select the color.
    Mail > Preferences > Composing > Message Format:  Rich Text
    Best.

  • How do I change the default window color?

    Having white screens is too bright for my eyes!! I always change the default window color in Windows (hiss hiss) to a light shade of gray and that setting carries thru to all windows (i.e. Word, Excel, notepad....). Is it possible to do a similar thing with Tiger? I see that I can choose between a couple of "schemes" from a "Desktop and Dashboard Settings" area (or similar - i don't have my mac here now so can't look to see the proper name) but I see no way to alter colors within those schemes. If you can tell me how to change the default color for my windows I will be awfully happy. thanks.

    Personally, I wouldn't trust it, and I don't hesitate to try these things most of the time even though they sometimes cause problems. But I've used Unsanity products before and they all require installing a preference pane called APE; Application Enhancement module, and that thing caused me lots of problems for my system, lots of crashes and flakiness. I won't use it again.
    But I'm sure there are lots of people using it happily, but if you don't feel confident in dealing with system problems stay away from anything that adds a system preference pane or goes up in the top menu bar at the top (Apple icons excepted) or has to start up with the system.

  • I want to change the size and color of text in call out boxes and text boxes. How can I do this? Jack

    I want to change the size and color of text in call out boxes and text boxes. How can I do this? Jack

    Highlite the text inside the text box and then press Ctrl+E.

  • How do I change the tab background color in Firefox 4?

    I just upgraded to Firefox 4. Tabs are now fine black font on dark grey background -- very hard to read. How do I change the tab background color?
    I have searched and the closest I can come is some instructions for modifying .css files, and it is not clear that those instructions will impact the tab background color.
    Thanks in advance for your help.

    Similar question asked by TH received another response.
    Here is the address of that question and answer:
    https://support.mozilla.com/en-US/questions/804464?s=change+tab+color+firefox+4&as=s
    I like the solution recommended there.
    Added information - after several days experience, I notice that some tabs occasionally revert to the original dark grey. So I am still looking for a better solution, ideally within Firefox rather than via add on. This seems like a basic setting for the browser that should be easy to change, rather than something so complex that I need an add on to change it. Or just build it without such a dark grey background to begin with and I would not need to change it.

  • How do I change the workspace background color?

    Hi all,
    I need to change the workspace background color from the
    default mid grey. But I can't find how to do this!
    Any ideas!
    Thanks in advance, Pedro.

    Sorry, but there's no way to change it from the default gray.
    Linda Rathgeber [PVII] **Adobe Community Expert-Fireworks**
    http://www.projectseven.com
    Fireworks Newsgroup:
    news://forums.projectseven.com/fireworks/
    CSS Newsgroup: news://forums.projectseven.com/css/
    Design Aid Kits:
    http://www.webdevbiz.com/pwf/index.cfm

  • How can i change the font and color in mail 5?

    how can i change the font and color in mail 5?

    Mail -> Preferences -> Fonts & Colors
    If you want to change the font and color in a message you're composing, you can right-click on the message and use the Font/Show Fonts command to bring up the Font panel (among other ways).
    Regards.

  • How do you change the workspace panel color in Edge Animate CC (the stage is OK) to a lighter gray, I have the dark gray now.  I have Win 7 Pro SP3?

    How do you change the workspace panel color in Edge Animate CC (the stage is OK) to a lighter gray, I have the dark gray now.  I have Win 7 Pro SP3?

    This is a feature as far as I know.
    On Sun, Dec 21, 2014 at 10:32 PM, Conquero <[email protected]>

Maybe you are looking for

  • Export in Discoverer 11g

    Hello , I have a Problem with the Web-Version of Oracle-Discoverer. I make an Export in Web-Discoverer 11g. My Result has 700 000 records and if I export this into for example a Text file then I get 177 000 records in this file. Not enough. The same

  • Mail w/attachments are received in body of mail

    I have an imac G5, Mac OS X (10.5.8), mail 3.6.  When I send an e-mail with an attachment, either a photo or a document, to a PC user, old or new, the attachment is received and shown in the body of the mail.  There IS NO attachment;  NO paper clip; 

  • Difference between oracle 9i database and oracle 9i lite

    Dear Sir/Mam, I like to know the performance and functionality difference between oracle 9i database and oracle9i lite. Is there is any performance variations between oracle 9i 9.0.1.1.1 and 9i 9.2.0.1.1

  • Can we Pass two variable values in to one Varaible which is Cust Exit?

    Hi all, Can we pass two Variable values to a Variable which is Custexit?(For Example posting Period and the fiscalyear in to the FicalPeriod ) Regards Kiran

  • JDK 1.4.1 for MacOS 9/X

    Hello, Excuse me for this (maybe) stupid question, but I wanted to download the last jdk 1.4.1 for Mac OS and it is not in the list of download. All other systems are listed (Windows, Linux, Solaris,...) but not Mac OS..? Is there a reason ? where an