mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
2 changed files with 59 additions and 5 deletions
@ -0,0 +1,53 @@
|
||||
package com.weis.darklaf.ui.table; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.table.TableCellEditor; |
||||
import javax.swing.table.TableCellRenderer; |
||||
import java.awt.*; |
||||
|
||||
public class DarkColorTableCellRendererEditor extends AbstractCellEditor implements TableCellRenderer, TableCellEditor { |
||||
|
||||
private final JLabel label; |
||||
private Color savedColor; |
||||
|
||||
public DarkColorTableCellRendererEditor() { |
||||
label = new JLabel(); |
||||
label.setOpaque(true); |
||||
} |
||||
|
||||
@Override |
||||
public Component getTableCellEditorComponent(final JTable table, final Object value, |
||||
final boolean isSelected, final int row, final int column) { |
||||
changeColor((Color) value); |
||||
SwingUtilities.invokeLater(() -> { |
||||
Color color = JColorChooser.showDialog(table, "Color Chooser", savedColor); |
||||
if (color == null) { |
||||
cancelCellEditing(); |
||||
} else { |
||||
changeColor(color); |
||||
} |
||||
}); |
||||
return label; |
||||
} |
||||
|
||||
@Override |
||||
public Object getCellEditorValue() { |
||||
return savedColor; |
||||
} |
||||
|
||||
private void changeColor(final Color color) { |
||||
if (color != null) { |
||||
savedColor = color; |
||||
label.setBackground(color); |
||||
System.out.println(color); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Component getTableCellRendererComponent(final JTable table, final Object value, |
||||
final boolean isSelected, final boolean hasFocus, |
||||
final int row, final int column) { |
||||
changeColor((Color) value); |
||||
return label; |
||||
} |
||||
} |
Loading…
Reference in new issue