ch.randelshofer.quaqua.QuaquaComboBoxCellRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Quaqua Show documentation
Show all versions of Quaqua Show documentation
A Mavenisation of the Quaqua Mac OSX Swing Look and Feel (Java library)
Quaqua Look and Feel (C) 2003-2010, Werner Randelshofer.
Mavenisation by Matt Gumbley, DevZendo.org - for problems with
Mavenisation, see Matt; for issues with Quaqua, see the Quaqua home page.
For full license details, see http://randelshofer.ch/quaqua/license.html
The newest version!
/*
* @(#)QuaquaComboBoxCellRenderer.java
*
* Copyright (c) 2004-2010 Werner Randelshofer, Immensee, Switzerland.
* All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the
* license agreement you entered into with Werner Randelshofer.
* For details see accompanying license terms.
*/
package ch.randelshofer.quaqua;
import java.awt.*;
import javax.swing.*;
/**
* QuaquaComboBoxCellRenderer.
*
* @author Werner Randelshofer
* @version $Id: QuaquaComboBoxCellRenderer.java 361 2010-11-21 11:19:20Z wrandelshofer $
*/
public class QuaquaComboBoxCellRenderer implements ListCellRenderer {
private ListCellRenderer valueRenderer;
private JPanel panel;
public QuaquaComboBoxCellRenderer(ListCellRenderer valueRenderer, boolean isInTable, boolean isEditable) {
this.valueRenderer = valueRenderer;
panel = new JPanel();
panel.setLayout(new BorderLayout());
if (isInTable) {
panel.setBorder(null);
} else {
if (isEditable) {
panel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3));
} else {
panel.setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
}
}
panel.setOpaque(true);
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component valueComponent = valueRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
panel.removeAll();
panel.add(valueComponent);
panel.setBackground((isSelected) ?
valueComponent.getBackground() :
UIManager.getColor("PopupMenu.background")
);
return panel;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy