📄 icontablecellrenderer.java
字号:
package openicq.gui;import java.awt.Color;import java.awt.Component;import javax.swing.*;import javax.swing.border.Border;import javax.swing.table.TableCellRenderer;/** * The <code>IconTableCellRenderer</code> class paints icons into the cells of * a table. * @author Hansgeorg Schwibbe * @copyright 2004 */public class IconTableCellRenderer extends JLabel implements TableCellRenderer{ private JLabel iconLabel = new JLabel(); /** * Initializes a new instance of the class <code>IconTableCellRenderer</code> * without any icon. */ public IconTableCellRenderer() { super(); } /** * Initializes a new instance of the class <code>IconTableCellRenderer</code> * with the specified icon. * @param iconSource the path to the specified icon */ public IconTableCellRenderer(String iconSource) { this.iconLabel.setIcon(new ImageIcon(iconSource)); } /** * Sets the path of the cell icon. * @param iconSource path of the icon */ public void setCellIconSource(String iconSource) { this.iconLabel.setIcon(new ImageIcon(iconSource)); } /** * Sets the background color of the cell. * @param bg the background color of the cell */ public void setCellBackground(Color bg) { this.iconLabel.setBackground(bg); } /** * Sets the foreground color of the cell. * @param fg the foreground color of the cell */ public void setCellForeground(Color fg) { this.iconLabel.setForeground(fg); } /** * Sets the border of the cell. * @param border the border of the cell */ public void setCellBorder(Border border) { this.iconLabel.setBorder(border); } /** * Sets the horizontal alignment of the text inside the cell. * @param alignment the horizontal alignment */ public void setCellHorizontalAlignment(int alignment) { this.iconLabel.setHorizontalAlignment(alignment); } /** * (non-Javadoc) * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, * java.lang.Object, boolean, boolean, int, int) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { iconLabel.setFont(table.getFont()); iconLabel.setEnabled(table.isEnabled()); iconLabel.setOpaque(table.isOpaque()); iconLabel.setText(String.valueOf(value)); return iconLabel; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -