Avoid costly component creation

This commit is contained in:
Roman Shevchenko
2012-09-03 13:44:49 +04:00
parent cbd277a8cf
commit 409fce99b4
2 changed files with 7 additions and 3 deletions
@@ -25,6 +25,8 @@ import java.awt.*;
* @author Vladimir Kondratyev
*/
public abstract class ColoredListCellRenderer extends SimpleColoredComponent implements ListCellRenderer {
private final ListCellRenderer myDefaultGtkRenderer = UIUtil.isUnderGTKLookAndFeel() ? new JComboBox().getRenderer() : null;
protected boolean mySelected;
protected Color myForeground;
protected Color mySelectionForeground;
@@ -60,8 +62,8 @@ public abstract class ColoredListCellRenderer extends SimpleColoredComponent imp
customizeCellRenderer(list, value, index, selected, hasFocus);
if (UIUtil.isUnderGTKLookAndFeel() && list.getModel() instanceof ComboBoxModel) {
final Component component = new JComboBox().getRenderer().getListCellRendererComponent(list, value, index, selected, hasFocus);
if (myDefaultGtkRenderer != null && list.getModel() instanceof ComboBoxModel) {
final Component component = myDefaultGtkRenderer.getListCellRendererComponent(list, value, index, selected, hasFocus);
if (component instanceof JLabel) {
return formatToLabel((JLabel)component);
}
@@ -30,6 +30,8 @@ import java.awt.*;
* @since 30.09.2010
*/
public abstract class ListCellRendererWrapper<T> implements ListCellRenderer {
private final ListCellRenderer myDefaultRenderer = new JComboBox().getRenderer();
private boolean mySeparator;
private Icon myIcon;
private String myText;
@@ -70,7 +72,7 @@ public abstract class ListCellRendererWrapper<T> implements ListCellRenderer {
return separator;
}
final Component component = new JComboBox().getRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final Component component = myDefaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (component instanceof JLabel) {
final JLabel label = (JLabel)component;
label.setIcon(myIcon);