📄 tableheaderrenderer.java
字号:
package org.dbgen.view;/****************************************************************************** * Copyright (c) 1996, Software Technologies Corporation, All Rights Reserved * * * * This program, and all the routines referenced herein, are the proprietary * * properties and trade secrets of SOFTWARE TECHNOLOGIES CORPORATION. * * * * Except as provided for by license agreement, this program shall not be * * duplicated, used or disclosed without the written consent, signed by an * * officer of SOFTWARE TECHNOLOGIES CORPORATION. * * * ******************************************************************************/import java.awt.*;import java.util.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.border.*;/** * <p> * MainPort class manages interaction between * all tabs in the main port screen * <p> [* @see related class ] * @author <author> */public class TableHeaderRenderer extends DefaultTableCellRenderer{ /* ********************************************************* */ /* CONSTANTS */ /* ********************************************************* */ public final static String RCS_ID="$Id: TableHeaderRenderer.java,v 1.2 2000/07/12 08:01:21 tomkwong Exp $"; /* ********************************************************* */ /* PACKAGE STATIC DATA */ /* ********************************************************* */ /* ********************************************************* */ /* PRIVATE STATIC DATA */ /* ********************************************************* */ /* ********************************************************* */ /* PUBLIC DATA */ /* ********************************************************* */ // use private keyword but supply public acess methods> /* ********************************************************* */ /* PACKAGE DATA */ /* ********************************************************* */ // use private keyword but supply access methods with no keyword /* ********************************************************* */ /* PROTECTED DATA */ /* ********************************************************* */ // use private keyword but supply protected access methods /* ********************************************************* */ /* PRIVATE DATA */ /* ********************************************************* */ // use private keyword and supply private access methods private JTableHeader header; private boolean pushed []; private BevelBorder border; /* ********************************************************* */ /* PACKAGE METHODS */ /* ********************************************************* */ /* ********************************************************* */ /* PROTECTED METHODS */ /* ********************************************************* */ /* ********************************************************* */ /* PRIVATE METHODS */ /* ********************************************************* */ /* ********************************************************* */ /* PUBLIC STATIC METHODS */ /* ********************************************************* */ /* ********************************************************* */ /* PACKAGE STATIC METHODS */ /* ********************************************************* */ /* ********************************************************* */ /* PRIVATE STATIC METHODS */ /* ********************************************************* */ /* ********************************************************* */ /* INNER CLASSES */ /* ********************************************************* */ class HeaderListener extends MouseAdapter { public void mousePressed (MouseEvent e) { int col = header.columnAtPoint(e.getPoint()); push(col); } public void mouseReleased (MouseEvent e) { int col = header.columnAtPoint(e.getPoint()); pop(col); } } /* ********************************************************* */ /* CONSTRUCTORS */ /* ********************************************************* */ public TableHeaderRenderer(TableModel model, JTableHeader header) { pushed = new boolean [model.getColumnCount ()]; this.header = header; this.header.setBorder(LineBorder.createBlackLineBorder()); this.header.setReorderingAllowed(false); setForeground (Color.black); setOpaque (true); setHorizontalAlignment(SwingConstants.CENTER); setFont( header.getFont() ); // add listener to header header.addMouseListener(new HeaderListener()); // Now set up the renderer to draw all headers. TableColumnModel tcm = header.getColumnModel(); for (int i = 0; i < tcm.getColumnCount (); i++) { TableColumn tc = tcm.getColumn(i); tc.setHeaderRenderer(this); } } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value == null) { setText(""); } else { setText(value.toString()); } if (pushed[column] == true) { border = new BevelBorder(BevelBorder.LOWERED); } else { border = new BevelBorder(BevelBorder.RAISED); } setBorder(border); return this; } /* ********************************************************* */ /* UNIT TEST */ /* ********************************************************* */ public static void main(String[] args) { } public void pop (int col) { if (col > -1 ) { pushed[col] = false; header.repaint(); } } /* ********************************************************* */ /* PUBLIC METHODS */ /* ********************************************************* */ /** * <p> * Handle the message sent by the notifier; * <p> * @param <parm> <description of parameter> * @param <parmN> <description of parameter> [ * <p> * @return <description of return value> ] [ * <p> * @execption <exception name> <description of when thrown> ] */ public void push (int col) { if (col > -1 ) { pushed[col] = true; header.repaint(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -