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


Java JTableHeader.getTable方法代码示例

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


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

示例1: mouseMoved

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
@Override
public void mouseMoved(MouseEvent evt) {
	TableColumn col = null;
	JTableHeader header = (JTableHeader) evt.getSource();
	JTable table = header.getTable();
	TableColumnModel colModel = table.getColumnModel();
	int vColIndex = colModel.getColumnIndexAtX(evt.getX());

	// Return if not clicked on any column header
	if (vColIndex >= 0) {
		col = colModel.getColumn(vColIndex);
	}

	if (col != curCol) {
		header.setToolTipText(tips.get(col));
		curCol = col;
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:19,代码来源:ColumnHeaderToolTips.java

示例2: mouseClicked

import javax.swing.table.JTableHeader; //导入方法依赖的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

示例3: mouseDragged

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
@Override
public void mouseDragged(MouseEvent e)
{
	int width = columnWidth - pressedX + e.getX();
	column.setPreferredWidth( width );
	JTableHeader header = (JTableHeader)e.getComponent();
	JTable table = header.getTable();
	table.setPreferredScrollableViewportSize(table.getPreferredSize());
	JScrollPane scrollPane = (JScrollPane)table.getParent().getParent();
	scrollPane.revalidate();
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:12,代码来源:DriverTable.java

示例4: mouseClicked

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader h = (JTableHeader) e.getSource();
    JTable table = h.getTable();
    int selectedRow = table.getSelectedRow();
    TableModel model = table.getModel();
    //remember selection to keep after sorting
    Object selectedAction=null;
    int objectColumn=-1;
    if(selectedRow>-1) {
        for(int i=0; i<table.getColumnCount(); i++) {
            //first find colum with appropriate object
            if(model.getValueAt(selectedRow, i) instanceof ActionHolder) {
                //remember this object
                selectedAction=model.getValueAt(selectedRow, i);
                objectColumn=i;
                //stop edition as we click somewhere ouside of editor
                TableCellEditor editor=table.getCellEditor();
                if(editor!=null) {
                    editor.stopCellEditing();
                }
                break;
            }
        }
    }
    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);
        //reselect the same object
        if(selectedAction!=null)setSelectedRow(table, selectedAction, objectColumn);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:TableSorter.java

示例5: mouseClicked

import javax.swing.table.JTableHeader; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
	if (e.getClickCount() == 2) {
		JTableHeader header = (JTableHeader) e.getSource();
		TableColumn tableColumn = getResizingColumn(header, e.getPoint());

		if (tableColumn == null) {
			return;
		}

		JTable table = header.getTable();

		if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
			if (table instanceof ExtendedJTable) {
				((ExtendedJTable) table).pack();
				e.consume();
			}
		} else {
			int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
			int width = (int) header.getDefaultRenderer()
					.getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col)
					.getPreferredSize().getWidth();

			int firstRow = 0;
			int lastRow = table.getRowCount();

			if (table instanceof ExtendedJTable) {
				ExtendedJScrollPane scrollPane = ((ExtendedJTable) table).getExtendedScrollPane();
				if (scrollPane != null) {
					JViewport viewport = scrollPane.getViewport();
					Rectangle viewRect = viewport.getViewRect();
					if (viewport.getHeight() < table.getHeight()) {
						firstRow = table.rowAtPoint(new Point(0, viewRect.y));
						firstRow = Math.max(0, firstRow);
						lastRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
						lastRow = Math.min(lastRow, table.getRowCount());
					}
				}
			}

			for (int row = firstRow; row < lastRow; row++) {
				int preferedWidth = (int) table.getCellRenderer(row, col)
						.getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col)
						.getPreferredSize().getWidth();
				width = Math.max(width, preferedWidth);
			}
			header.setResizingColumn(tableColumn); // this line is very important
			tableColumn.setWidth(width + table.getIntercellSpacing().width);

			e.consume();
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:54,代码来源:ExtendedJTableColumnFitMouseListener.java


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