⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e936. creating a custom column header renderer in a jtable component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
The default column header renderer simply display a single line of text. If you need to display something other than this, you will need to build and install your own column header renderer. This example defines a generic renderer and installs it on a column. 
See e928 Creating a Custom Cell Renderer in a JTable Component for more information about renderers. 

    JTable table = new JTable();
    // Add data...
    
    // Install the custom header renderer on the first visible column
    int vColIndex = 0;
    TableColumn col = table.getColumnModel().getColumn(vColIndex);
    col.setHeaderRenderer(new MyTableHeaderRenderer());
    
    
    public class MyTableHeaderRenderer extends JLabel implements TableCellRenderer {
        // This method is called each time a column header
        // using this renderer needs to be rendered.
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
            // 'value' is column header value of column 'vColIndex'
            // rowIndex is always -1
            // isSelected is always false
            // hasFocus is always false
    
            // Configure the component with the specified value
            setText(value.toString());
    
            // Set tool tip if desired
            setToolTipText((String)value);
    
            // Since the renderer is a component, return itself
            return this;
        }
    
        // The following methods override the defaults for performance reasons
        public void validate() {}
        public void revalidate() {}
        protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {}
        public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
    }

⌨️ 快捷键说明

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