当前位置: 首页>>代码示例>>Java>>正文


Java TableColumnModel类代码示例

本文整理汇总了Java中javax.swing.table.TableColumnModel的典型用法代码示例。如果您正苦于以下问题:Java TableColumnModel类的具体用法?Java TableColumnModel怎么用?Java TableColumnModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TableColumnModel类属于javax.swing.table包,在下文中一共展示了TableColumnModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDefaultColumnsFromModel

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
@Override
public void createDefaultColumnsFromModel() {
    TableModel m = getModel();
    if( m != null ) {
        // Remove any current columns
        TableColumnModel cm = getColumnModel();
        while( cm.getColumnCount() > 0 ) {
            cm.removeColumn( cm.getColumn(0) );
 }

        // Create new columns from the data model info
        for( int i=0; i<m.getColumnCount(); i++ ) {
            TableColumn newColumn = new MyTableColumn(i);
            if( i == TaskListModel.COL_LOCATION )
                newColumn.setCellRenderer( new LeftDotRenderer() );
            else if( i != TaskListModel.COL_GROUP )
                newColumn.setCellRenderer( new TooltipRenderer() );
            addColumn(newColumn);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TaskListTable.java

示例2: addMouseListenerToHeaderInTable

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
public void addMouseListenerToHeaderInTable(JTable table) { 
    final TableSorter sorter = this; 
    final JTable tableView = table; 
    tableView.setColumnSelectionAllowed(false); 
    MouseAdapter listMouseListener = new MouseAdapter() {
        boolean ascending = false;
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX()); 
            int column = tableView.convertColumnIndexToModel(viewColumn); 
            if (e.getClickCount() == 1 && column != -1) {
                //System.out.println("Sorting ..."); 
                //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; 
                //boolean ascending = (shiftPressed == 0);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:27,代码来源:TableSorter.java

示例3: mouseClicked

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
public void mouseClicked(MouseEvent e) {

            JTableHeader     h           = (JTableHeader) e.getSource();
            TableColumnModel columnModel = h.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = columnModel.getColumn(viewColumn).getModelIndex();

            if (column != -1) {
                int status = getSortingStatus(column);

                if (!e.isControlDown()) {
                    cancelSorting();
                }

                // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                status = status + (e.isShiftDown() ? -1
                                                   : 1);
                status = (status + 4) % 3 - 1;    // signed mod, returning {-1, 0, 1}

                setSortingStatus(column, status);
            }
        }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:TableSorter.java

示例4: mousePressed

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent e)
{
	JTableHeader header = (JTableHeader)e.getComponent();
	TableColumnModel tcm = header.getColumnModel();
	int columnIndex = tcm.getColumnIndexAtX( e.getX() );
	Cursor cursor = header.getCursor();

	if (columnIndex == tcm.getColumnCount() - 1
	&&  cursor == Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR))
	{
		column = tcm.getColumn( columnIndex );
		columnWidth = column.getWidth();
		pressedX = e.getX();
		header.addMouseMotionListener( this );
	}
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:18,代码来源:DriverTable.java

示例5: run

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
@Override
public void run() {            
    TableColumnModel cm = table.getColumnModel();
    int count = cm.getColumnCount();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < count; i++) {
        if(!tableModel.getColumnId(i).equals(IssueNode.LABEL_NAME_SEEN)) {
            sb.append(tableModel.getColumnId(i));
            sb.append(CONFIG_DELIMITER);
            sb.append(cm.getColumn(i).getWidth());
            if(i < count - 1) {
                sb.append(CONFIG_DELIMITER);
            }
        }
    }
    storeColumns(repositoryId, sb.toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:IssueTable.java

示例6: mouseClicked

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader h = (JTableHeader) e.getSource();
    TableColumnModel columnModel = h.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = columnModel.getColumn(viewColumn).getModelIndex();
    if (column != -1) {
        int status = getSortingStatus(column);
        if (!e.isControlDown()) {
            cancelSorting();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or 
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. 
        status += e.isShiftDown() ? -1 : 1;
        status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setSortingStatus(column, status);
        if(issueTable != null) {
            issueTable.sortOrderChanged();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TableSorter.java

示例7: setupColumns

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
private void setupColumns() {
    ResourceBundle loc = NbBundle.getBundle(DiffTreeTable.class);
    setPropertyColumns(RevisionNode.COLUMN_NAME_PATH, loc.getString("LBL_DiffTree_Column_Path"), //NOI18N
            RevisionNode.COLUMN_NAME_DATE, loc.getString("LBL_DiffTree_Column_Time"), //NOI18N
            RevisionNode.COLUMN_NAME_USERNAME, loc.getString("LBL_DiffTree_Column_Username"), //NOI18N
            RevisionNode.COLUMN_NAME_MESSAGE, loc.getString("LBL_DiffTree_Column_Message")); //NOI18N
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_PATH, loc.getString("LBL_DiffTree_Column_Path_Desc"));
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_DATE, loc.getString("LBL_DiffTree_Column_Time_Desc")); //NOI18N
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_USERNAME, loc.getString("LBL_DiffTree_Column_Username_Desc")); //NOI18N
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_MESSAGE, loc.getString("LBL_DiffTree_Column_Message_Desc")); //NOI18N
    TableColumnModel model = getOutline().getColumnModel();
    if (model instanceof ETableColumnModel) {
        ((ETableColumnModel) model).setColumnHidden(model.getColumn(1), true);
    }
    TableColumn column = getOutline().getColumn(loc.getString("LBL_DiffTree_Column_Message"));
    column.setCellRenderer(new MessageRenderer(getOutline().getDefaultRenderer(String.class)));
    setDefaultColumnSizes();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:DiffTreeTable.java

示例8: mouseClicked

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader header = (JTableHeader) e.getSource();
    JTable table = header.getTable();
    TableColumnModel columnModel = table.getColumnModel();
    int vci = columnModel.getColumnIndexAtX(e.getX());
    int mci = table.convertColumnIndexToModel(vci);
    if (mci == targetColumnIndex) {
        if (SwingUtilities.isLeftMouseButton(e)) {
            TableColumn column = columnModel.getColumn(vci);
            Object v = column.getHeaderValue();
            boolean b = Status.DESELECTED.equals(v);
            TableModel m = table.getModel();
            for (int i = 0; i < m.getRowCount(); i++) {
                m.setValueAt(b, i, mci);
            }
            column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
        } else if (SwingUtilities.isRightMouseButton(e)) {
            if (popupMenu != null) {
                popupMenu.show(table, e.getX(), 0);
            }
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:25,代码来源:TableCheckBoxColumn.java

示例9: MyTableHeader

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
public MyTableHeader( TableColumnModel model ) {
    super( model );
    addMouseListener( new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if( e.getClickCount() != 1 )
                return;
            int column = columnAtPoint( e.getPoint() );
            if( column > 0 && getModel() instanceof TaskListModel ) {
                ((TaskListModel)getModel()).toggleSort( column );
                repaint();
            }
        }
    });
    this.setReorderingAllowed( false );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TaskListTable.java

示例10: updateTableColumnSizes

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
private void updateTableColumnSizes() {
    ETable table = tableView.getTable();
    Font font = tableView.getFont();
    FontMetrics fm = tableView.getFontMetrics(font);
    int maxCharWidth = fm.charWidth('A');
    int editingBorder = 4;
    TableColumnModel columnModel = table.getColumnModel();

    TableColumn nameColumn = columnModel.getColumn(0);
    nameColumn.setPreferredWidth(8 * maxCharWidth + editingBorder); // 8 chars for name

    TableColumn keyColumn = columnModel.getColumn(1);
    // Single char for key (but 3 chars to prevent "..." in column header)
    keyColumn.setPreferredWidth(3 * maxCharWidth + editingBorder);
    keyColumn.setMinWidth(keyColumn.getPreferredWidth());

    TableColumn locationColumn = columnModel.getColumn(2);
    Insets insets = tableView.getBorder().getBorderInsets(tableView);
    int remainingWidth = tableView.getParent().getWidth() - insets.left - insets.right;
    remainingWidth -= 2 * columnModel.getColumnMargin();
    remainingWidth -= nameColumn.getPreferredWidth();
    remainingWidth -= keyColumn.getPreferredWidth();
    locationColumn.setPreferredWidth(remainingWidth); // remaining space for location
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:BookmarksView.java

示例11: adjustColumnRatios

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
public void adjustColumnRatios()
{
	TableColumnModel m = getColumnModel();
	if (m == null) return;
	TableColumn c;
	int ii;
	for (ii = 0; ii < m.getColumnCount()-1; ii++)
	{
		c = m.getColumn(ii);
		c.setCellRenderer(seqRenderer);
		c.setMinWidth(35);
		c.setPreferredWidth(100);
		c.setMaxWidth(Integer.MAX_VALUE/2);
	}

	if (ii < m.getColumnCount())
	{
		c = m.getColumn(ii);
		c.setCellRenderer(totalRenderer);
		c.setMinWidth(70);
		c.setPreferredWidth(200);
		c.setMaxWidth(Integer.MAX_VALUE);
	}
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:25,代码来源:Timer.java

示例12: setColumnsData

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
private void setColumnsData() {
    barRenderer = getBarCellRenderer();

    TableColumnModel colModel = resTable.getColumnModel();
    colModel.getColumn(0).setPreferredWidth(minNamesColumnWidth);

    int index;

    for (int i = 0; i < colModel.getColumnCount(); i++) {
        index = resTableModel.getRealColumn(i);

        if (index == 0) {
            colModel.getColumn(i).setPreferredWidth(minNamesColumnWidth);
        } else {
            colModel.getColumn(i).setPreferredWidth(columnWidths[index - 1]);
        }

        if (index == 1) {
            colModel.getColumn(i).setCellRenderer(barRenderer);
        } else {
            colModel.getColumn(i).setCellRenderer(columnRenderers[index]);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SampledResultsPanel.java

示例13: setColumnsData

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
protected void setColumnsData() {
    int index;
    TableColumnModel colModel = treeTable.getColumnModel();

    treeTable.setTreeCellRenderer(enhancedTreeCellRenderer);
    colModel.getColumn(0).setPreferredWidth(minNamesColumnWidth);

    for (int i = 0; i < treeTableModel.getColumnCount(); i++) {
        index = treeTableModel.getRealColumn(i);

        if (index != 0) {
            colModel.getColumn(i).setPreferredWidth(columnWidths[index - 1]);
            colModel.getColumn(i).setCellRenderer(columnRenderers[index]);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ReverseMemCallGraphPanel.java

示例14: setColumnsData

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
private void setColumnsData() {
    int index;
    TableColumnModel colModel = treeTable.getColumnModel();

    treeTable.setTreeCellRenderer(enhancedTreeCellRenderer);
    colModel.getColumn(0).setPreferredWidth(minNamesColumnWidth);

    for (int i = 0; i < treeTableModel.getColumnCount(); i++) {
        index = treeTableModel.getRealColumn(i);

        if (index != 0) {
            colModel.getColumn(i).setPreferredWidth(columnWidths[index - 1]);
            colModel.getColumn(i).setCellRenderer(columnRenderers[index]);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SubtreeCallGraphPanel.java

示例15: getRenderer

import javax.swing.table.TableColumnModel; //导入依赖的package包/类
Component getRenderer(TableCellRenderer renderer, int row, int column, boolean sized) {
        isCustomRendering = true;
        try {
            Component comp = prepareRenderer(renderer, row, column);
//            comp.setSize(comp.getPreferredSize().width, getRowHeight());
            if (sized) {
                comp.setSize(comp.getPreferredSize().width, getRowHeight());
                if (!isLeadingAlign(comp)) {
                    TableColumnModel m = getColumnModel();
                    int x = -comp.getWidth();
                    int c = m.getColumn(column).getWidth();
                    int _column = convertColumnIndexToModel(column);
                    if (isScrollableColumn(_column)) {
                        x += Math.max(c, getColumnPreferredWidth(_column));
                    } else {
                        x += c;
                    }
                    comp.move(x - m.getColumnMargin(), 0);
                }
            }
            
            return comp;
        } finally {
            isCustomRendering = false;
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ProfilerTable.java


注:本文中的javax.swing.table.TableColumnModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。