Changeset 12947 in josm


Ignore:
Timestamp:
2017-10-08T15:02:10+02:00 (13 days ago)
Author:
bastiK
Message:

see #15410 - set cell renderer only for 2nd column, not entire table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r12946 r12947  
    55
    66import java.awt.Color;
     7import java.awt.Component;
    78import java.awt.Dimension;
    89import java.awt.GridBagLayout;
     
    2728import javax.swing.ListSelectionModel;
    2829import javax.swing.event.ListSelectionEvent;
     30import javax.swing.table.DefaultTableCellRenderer;
    2931import javax.swing.table.DefaultTableModel;
    30 import javax.swing.table.TableCellRenderer;
    3132
    3233import org.openstreetmap.josm.Main;
     
    4647import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
    4748import org.openstreetmap.josm.gui.util.GuiHelper;
    48 import org.openstreetmap.josm.spi.preferences.Config;
    4949import org.openstreetmap.josm.tools.ColorHelper;
    5050import org.openstreetmap.josm.tools.GBC;
     
    218218        });
    219219        colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    220         final TableCellRenderer oldColorsRenderer = colors.getDefaultRenderer(Object.class);
    221         colors.setDefaultRenderer(Object.class, (t, o, selected, focus, row, column) -> {
    222             if (o == null)
    223                 return new JLabel();
    224             if (column == 1) {
    225                 Color c = (Color) o;
    226                 JLabel l = new JLabel(ColorHelper.color2html(c));
    227                 GuiHelper.setBackgroundReadable(l, c);
    228                 l.setOpaque(true);
    229                 return l;
    230             }
    231             return oldColorsRenderer.getTableCellRendererComponent(t, getName(o.toString()), selected, focus, row, column);
     220        colors.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
     221            @Override
     222            public Component getTableCellRendererComponent(
     223                    JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     224                Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     225                if (value != null && comp instanceof JLabel) {
     226                    JLabel label = (JLabel) comp;
     227                    Color c = (Color) value;
     228                    label.setText(ColorHelper.color2html(c));
     229                    GuiHelper.setBackgroundReadable(label, c);
     230                    label.setOpaque(true);
     231                    return label;
     232                }
     233                return comp;
     234            }
    232235        });
    233236        colors.getColumnModel().getColumn(1).setWidth(100);
Note: See TracChangeset for help on using the changeset viewer.