🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.gui
Article #34

ComboBox for Windows L&F refuse changing its color

#34
From: Thomas Fichtenbauer
Date: Thu, 30 Nov 2000 00:00
58 lines
2723 bytes
ComboBox for Windows L&F seems to refuse changing its background and
foreground. When the background and foreground are set to a new color,
the new color only ficker in the combo box area when the user select a
new item but immediately replaced by the old color (dark blue and
white). But the Metal L&F ComboBox works as expected (new color stays).
Is there a way around this. I just want the Metal Feel but the Windows
Look. I am using swing JDK 1.2.2 but i have also tried with JDK 1.3.
Here are the code that show this:

////////////////////////////////////////////////////////////////////

import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import com.sun.java.swing.plaf.*;
import com.sun.java.swing.*;

public class ComboTest extends WindowAdapter {

public static void main(String[] args) {

// true for Windows L&F - background always dark blue and foreground
// always white even after explicitly setting background to
// diferrent color.
// false for Metal L&F - this seems to work as expected, back and
// foreground always the same set color.
if(true) {
try {
UIManager.setLookAndFeel( new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
} catch(UnsupportedLookAndFeelException e) { }
}

JFrame frame = new JFrame();
frame.addWindowListener(new ComboTest());
frame.setSize(100, 50);

String[] stuffs = { "Hello", "World", "How", "are", "you", "today" };

JComboBox combo = new JComboBox(stuffs);

// Change background and foreground to be green and red. This won't work

// if in Windows L&F.
combo.setBackground(Color.green);
combo.setForeground(Color.red);

frame.getContentPane().add(combo);

frame.setVisible(true);
}

public void windowClosing(WindowEvent e) {
System.exit(0);
}

}
Technical Details
Message-ID: <3A260DEF.113F326C@xsoft.at>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,15e294b3e888163a,start
X-Google-Attributes: gid111d45,public
X-Google-Thread: 10fd6d,15e294b3e888163a,start
X-Google-Attributes: gid10fd6d,public
From: Thomas Fichtenbauer <t.fichtenbauer@xsoft.at>
Subject: ComboBox for Windows L&F refuse changing its color
Date: 2000/11/30
Message-ID: <3A260DEF.113F326C@xsoft.at>
X-Deja-AN: 699434247
Cache-Post-Path: newsproxy1.debis.at!unknown@hide.xsoft.at
Content-Transfer-Encoding: 7bit
X-Accept-Language: de
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@kpnqwest.at
X-Trace: nreader1.kpnqwest.net 975572464 53.244.2.18 (Thu, 30 Nov 2000 09:21:04 MET)
Organization: debis.at
X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/)
MIME-Version: 1.0
NNTP-Posting-Date: Thu, 30 Nov 2000 09:21:04 MET
Newsgroups: comp.lang.java.gui,borland.public.jbuilder.java.swing