1 19 20 package org.netbeans.modules.tasklist.usertasks.renderers; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.awt.Rectangle ; 25 26 import javax.swing.JPanel ; 27 import javax.swing.JProgressBar ; 28 import javax.swing.UIManager ; 29 import javax.swing.border.Border ; 30 import javax.swing.border.EmptyBorder ; 31 import javax.swing.border.LineBorder ; 32 import javax.swing.table.DefaultTableCellRenderer ; 33 import javax.swing.table.TableCellRenderer ; 34 35 import org.openide.util.NbBundle; 36 37 40 public class PercentsTableCellRenderer extends JPanel implements TableCellRenderer { 41 protected static Border noFocusBorder = new EmptyBorder (2, 2, 2, 2); 42 43 private JProgressBar progressBar; 44 private DefaultTableCellRenderer def = new DefaultTableCellRenderer (); 45 46 49 public PercentsTableCellRenderer() { 50 setOpaque(true); 51 progressBar = new JProgressBar (); 52 progressBar.setStringPainted(true); 53 progressBar.setOpaque(true); 54 progressBar.setBorderPainted(false); 55 56 setLayout(new BorderLayout ()); 57 add(progressBar, BorderLayout.CENTER); 58 } 59 60 public Component getTableCellRendererComponent(javax.swing.JTable table, 61 Object value, boolean isSelected, boolean hasFocus, 62 int row, int column) { 63 if (value == null) 64 return def.getTableCellRendererComponent(table, value, isSelected, 65 hasFocus, row, column); 66 67 if (isSelected) { 68 setBackground(table.getSelectionBackground()); 69 } 70 else { 71 setBackground(table.getBackground()); 72 } 73 int n = ((Integer ) value).intValue(); 74 progressBar.setValue(n); 75 progressBar.setString(n + "%"); if (hasFocus) { 77 setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") ); } else { 79 setBorder(null); 80 } 81 return this; 82 } 83 } 84 | Popular Tags |