🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.gui
1 messages
1 total messages Started by Thomas Fichtenbauer Thu, 30 Nov 2000 00:00
ComboBox for Windows L&F refuse changing its color
#34
Author: 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);
}

}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads