Hi,

 

I discovered a bug with ComboBoxCellRenderer  when using the Windows Look and Feel.  The selected item doesn’t show in the ComboBox.   I used the example renderer from the Canoo api.   Attached is a test case.

 

Any suggestions?  I assume I will need to create an extension.

 

Thanks,

 

Les

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.BorderFactory;
import com.ulcjava.base.application.IComboBoxCellRenderer;
import com.ulcjava.base.application.IRendererComponent;
import com.ulcjava.base.application.ULCBorderLayoutPane;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCComboBox;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCLabel;
import com.ulcjava.base.application.util.Color;
import com.ulcjava.base.development.DevelopmentRunner;

public class ComboBoxRendererTest extends AbstractApplication {

	public void start() {
		
		ULCFrame frame = new ULCFrame("ULC ComboBox Test");
		ULCBorderLayoutPane pane = new ULCBorderLayoutPane();

		frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
		
		pane.add(createTestPane(), ULCBorderLayoutPane.CENTER);
		frame.add(pane);
		frame.pack();
		frame.setVisible(true);
	}

	private ULCBoxPane createTestPane() {
		ULCBoxPane pane = new ULCBoxPane();
		pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
		
		String [] values = new String[] { "one", "two", "three" };
		
		ULCComboBox combo = new ULCComboBox(values);
		combo.setRenderer(new SampleRenderer());
		
		pane.add(ULCBoxPane.BOX_EXPAND_CENTER, combo);

		return pane;
	}

	private static class SampleRenderer implements IComboBoxCellRenderer {
	     private ULCLabel fLabel;

	     public SampleRenderer() {
	         fLabel = new ULCLabel();
	     }

	     public IRendererComponent getComboBoxCellRendererComponent(
	             ULCComboBox comboBox, Object value,
	             boolean isSelected, int row) {

	         fLabel.setBackground(isSelected ? Color.yellow : comboBox.getBackground());
	         return fLabel;
	     }
	 }
	 
	public static void main(String[] args) {
		
	    try {
	         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	     } catch (UnsupportedLookAndFeelException ex) {
	         ex.printStackTrace();
	     } catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DevelopmentRunner.setApplicationClass(ComboBoxRendererTest.class);
		DevelopmentRunner.run();
	}	
	
}

Reply via email to