radiobuttontablecellrenderer.java

来自「一个类似QQ的在线通讯聊天软件原码,适合初学者参考学习。」· Java 代码 · 共 41 行

JAVA
41
字号
package openicq.gui;import java.awt.Component;import javax.swing.*;import javax.swing.table.TableCellRenderer;/** * The <code>RadioButtonTableCellRenderer</code> class is a custom table cell * renderer for radio buttons in tables. * @author Hansgeorg Schwibbe * @copyright 2004 */public class RadioButtonTableCellRenderer implements TableCellRenderer{  private JRadioButton radioButton;  /**   * (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)  {    if (value instanceof JRadioButton)    {      radioButton = (JRadioButton) value;      radioButton.setBackground(table.getBackground());      radioButton.setForeground(table.getForeground());      radioButton.setFont(table.getFont());      radioButton.setEnabled(table.isEnabled());      radioButton.setOpaque(table.isOpaque());      radioButton.setHorizontalAlignment((int) Component.CENTER_ALIGNMENT);      return radioButton;    }    return new JLabel(String.valueOf(value));  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?