| 1 | |
package br.mia.test.model; |
| 2 | |
|
| 3 | |
import java.awt.Component; |
| 4 | |
|
| 5 | |
import javax.swing.JComboBox; |
| 6 | |
import javax.swing.JTable; |
| 7 | |
import javax.swing.table.TableCellRenderer; |
| 8 | |
|
| 9 | |
public class MyComboBoxRenderer extends JComboBox implements TableCellRenderer { |
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
private static final long serialVersionUID = 1L; |
| 14 | |
public MyComboBoxRenderer(String[] items) { |
| 15 | 0 | super(items); |
| 16 | 0 | } |
| 17 | |
|
| 18 | |
public MyComboBoxRenderer(Object[] items) { |
| 19 | 0 | super(items); |
| 20 | |
|
| 21 | 0 | } |
| 22 | |
public Component getTableCellRendererComponent(JTable table, Object value, |
| 23 | |
boolean isSelected, boolean hasFocus, int row, int column) { |
| 24 | 0 | if (isSelected) { |
| 25 | 0 | setForeground(table.getSelectionForeground()); |
| 26 | 0 | super.setBackground(table.getSelectionBackground()); |
| 27 | |
} else { |
| 28 | 0 | setForeground(table.getForeground()); |
| 29 | 0 | setBackground(table.getBackground()); |
| 30 | |
} |
| 31 | |
|
| 32 | |
|
| 33 | 0 | setSelectedItem(value); |
| 34 | 0 | return this; |
| 35 | |
} |
| 36 | |
} |