javax.swing.table.JTableHeader#getColumnModel ( )源码实例Demo

下面列出了javax.swing.table.JTableHeader#getColumnModel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: TableSorter.java
@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();
        }
    }
}
 
源代码2 项目: netbeans   文件: TableSorter.java
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);
    }
}
 
源代码3 项目: evosql   文件: TableSorter.java
public void mouseClicked(MouseEvent e) {

            JTableHeader     h           = (JTableHeader) e.getSource();
            TableColumnModel columnModel = h.getColumnModel();
            int              viewColumn  = h.columnAtPoint(e.getPoint());
            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);
            }
        }
 
源代码4 项目: Logisim   文件: TableSorter.java
@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 = status + (e.isShiftDown() ? -1 : 1);
		status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0,
										// 1}
		setSortingStatus(column, status);
	}
}
 
源代码5 项目: rapidminer-studio   文件: FileTable.java
@Override
public void mouseClicked(MouseEvent e) {
	if (!e.isPopupTrigger()) {
		JTableHeader h = (JTableHeader) e.getSource();
		TableColumnModel columnModel = h.getColumnModel();
		int viewColumn = columnModel.getColumnIndexAtX(e.getX());
		int column = columnModel.getColumn(viewColumn).getModelIndex();
		if (column != -1) {
			if (columnModel.getColumn(viewColumn).getHeaderValue().equals(FILE_NAME)) {
				FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_NAME, false);
				FileTable.this.fileList.updateTableData();
			} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals(TYPE)) {
				FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_TYPE, false);
				FileTable.this.fileList.updateTableData();
			} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals(LAST_MODIFIED)) {
				FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_MODIFIED, false);
				FileTable.this.fileList.updateTableData();
			} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals(SIZE)) {
				FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_SIZE, false);
				FileTable.this.fileList.updateTableData();
			}
		}
	}
}
 
@Override
public void mouseClicked(MouseEvent e) {
	JTableHeader h = (JTableHeader) e.getSource();
	TableColumnModel columnModel = h.getColumnModel();
	int viewColumn = getSortingColumnIndex(h, e.getPoint());
	if (viewColumn != -1) {
		int column = columnModel.getColumn(viewColumn).getModelIndex();
		if (column != -1) {
			int status = getSortingStatus(column);
			if (!SwingTools.isControlOrMetaDown(e)) {
				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);
		}
		e.consume();
	}
}
 
源代码7 项目: rapidminer-studio   文件: ExtendedJTable.java
public void setSortingStatus(final int status, final boolean cancelSorting) {
	if (getModel() instanceof ExtendedJTableSorterModel) {
		ExtendedJTableSorterModel sorterModel = (ExtendedJTableSorterModel) getModel();

		JTableHeader h = getTableHeader();
		TableColumnModel columnModel = h.getColumnModel();
		int viewColumn = getSelectedColumn();
		if (viewColumn != -1) {
			int column = columnModel.getColumn(viewColumn).getModelIndex();
			if (column != -1) {
				if (sorterModel.isSorting()) {
					if (cancelSorting) {
						sorterModel.cancelSorting();
					}
				}
				sorterModel.setSortingStatus(column, status);
			}
		}
	}
}
 
源代码8 项目: binnavi   文件: CTableSorter.java
@Override
public void mouseClicked(final MouseEvent e) {
  final JTableHeader h = (JTableHeader) e.getSource();
  final TableColumnModel columnModel = h.getColumnModel();
  final int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  final 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);
  }
}
 
源代码9 项目: jplag   文件: TableSorter.java
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);
    }
}
 
源代码10 项目: snap-desktop   文件: AOISortingDecorator.java
@Override
        public void mouseClicked(final MouseEvent e) {
            final JTableHeader h = (JTableHeader) e.getSource();
            final TableColumnModel columnModel = h.getColumnModel();
            final int viewColumnIndex = columnModel.getColumnIndexAtX(e.getX());
            final int columnIndex = columnModel.getColumn(viewColumnIndex).getModelIndex();
            if (columnIndex != -1) {
                int direction = getSortingDirection(columnIndex);
                if (!e.isControlDown()) {
                    clearSortingDirections();
//                    viewToModel = null;
//                    fireTableDataChanged();
                    _tableHeader.repaint();
                }
                // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                direction += (e.isShiftDown() ? -1 : 1);
                direction = (direction + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                setDirectionForColumn(columnIndex, direction);
//                viewToModel = null;
                initViewToModel();
                fireTableDataChanged();
            }
        }
 
源代码11 项目: java-swing-tips   文件: SortableTableModel.java
@Override public void mousePressed(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  TableColumnModel columnModel = h.getColumnModel();
  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  if (viewColumn < 0) {
    return;
  }
  TableCellRenderer tcr = h.getDefaultRenderer();
  int column = columnModel.getColumn(viewColumn).getModelIndex();
  if (column != -1 && tcr instanceof SortButtonRenderer) {
    SortButtonRenderer sbr = (SortButtonRenderer) tcr;
    sbr.setPressedColumn(column);
    sbr.setSelectedColumn(column);
    h.repaint();
    JTable table = h.getTable();
    if (table.isEditing()) {
      table.getCellEditor().stopCellEditing();
    }
    SortableTableModel model = (SortableTableModel) table.getModel();
    model.sortByColumn(column, SortButtonRenderer.DOWN == sbr.getState(column));
  }
}
 
源代码12 项目: java-swing-tips   文件: SortableTableModel.java
@Override public void mousePressed(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  TableColumnModel columnModel = h.getColumnModel();
  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  if (viewColumn < 0) {
    return;
  }
  TableCellRenderer tcr = h.getDefaultRenderer();
  int column = columnModel.getColumn(viewColumn).getModelIndex();
  if (column != -1 && tcr instanceof SortButtonRenderer) {
    SortButtonRenderer sbr = (SortButtonRenderer) tcr;
    sbr.setPressedColumn(column);
    sbr.setSelectedColumn(column);
    h.repaint();
    JTable table = h.getTable();
    if (table.isEditing()) {
      table.getCellEditor().stopCellEditing();
    }
    SortableTableModel model = (SortableTableModel) table.getModel();
    model.sortByColumn(column, SortButtonRenderer.DOWN == sbr.getState(column));
  }
}
 
源代码13 项目: snap-desktop   文件: SortingDecorator.java
@Override
public void mouseClicked(final MouseEvent e) {
    final JTableHeader h = (JTableHeader) e.getSource();
    final TableColumnModel columnModel = h.getColumnModel();
    final int viewColumnIndex = columnModel.getColumnIndexAtX(e.getX());
    final int columnIndex = columnModel.getColumn(viewColumnIndex).getModelIndex();
    if (columnIndex != -1) {
        int direction = getSortingDirection(columnIndex);
        if (!e.isControlDown()) {
            clearSortingDirections();
            _tableHeader.repaint();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
        direction += (e.isShiftDown() ? -1 : 1);
        direction = (direction + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setDirectionForColumn(columnIndex, direction);
        doSortBy = false;
        initViewToModel();
        fireTableDataChanged();
    }
}
 
源代码14 项目: java-swing-tips   文件: MainPanel.java
@Override public void paint(Graphics g, JComponent c) {
  super.paint(g, c);
  if (c instanceof JLayer) {
    JScrollPane scroll = (JScrollPane) ((JLayer<?>) c).getView();
    JTable table = (JTable) scroll.getViewport().getView();
    JTableHeader header = table.getTableHeader();

    int width = header.getWidth();
    TableColumnModel cm = header.getColumnModel();
    for (int i = 0; i < cm.getColumnCount(); i++) {
      width -= cm.getColumn(i).getWidth();
    }

    Point pt = SwingUtilities.convertPoint(header, 0, 0, c);
    filler.setLocation(pt.x + header.getWidth() - width, pt.y);
    filler.setSize(width, header.getHeight());
    fillerColumn.setWidth(width);

    SwingUtilities.paintComponent(g, filler, tempTable, filler.getBounds());
  }
}
 
源代码15 项目: java-swing-tips   文件: SortableTableModel.java
@Override public void mousePressed(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  TableColumnModel columnModel = h.getColumnModel();
  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  if (viewColumn < 0) {
    return;
  }
  TableCellRenderer tcr = h.getDefaultRenderer();
  int column = columnModel.getColumn(viewColumn).getModelIndex();
  if (column != -1 && tcr instanceof SortButtonRenderer) {
    SortButtonRenderer sbr = (SortButtonRenderer) tcr;
    if (!sbr.isEnabledAt(column)) {
      return;
    }
    sbr.setPressedColumn(column);
    sbr.setSelectedColumn(column);
    h.repaint();
    JTable table = h.getTable();
    if (table.isEditing()) {
      table.getCellEditor().stopCellEditing();
    }
    SortableTableModel model = (SortableTableModel) table.getModel();
    model.sortByColumn(column, SortButtonRenderer.DOWN == sbr.getState(column));
  }
}
 
源代码16 项目: java-swing-tips   文件: TableSorter.java
@Override public void mouseClicked(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  TableColumnModel columnModel = h.getColumnModel();
  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  // ArrayIndexOutOfBoundsException: -1
  if (viewColumn < 0) {
    return;
  }
  int column = columnModel.getColumn(viewColumn).getModelIndex();
  if (column != -1) {
    int status = getSortingStatus(column) + (e.isShiftDown() ? -1 : 1);
    if (!e.isControlDown()) {
      cancelSorting();
    }
    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
    // int d = e.isShiftDown() ? -1 : 1;
    // status = status + d;
    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
    setSortingStatus(column, status);
  }
}
 
源代码17 项目: marathonv5   文件: JTableHeaderJavaElement.java
private List<IJavaElement> findmatch(ArrayList<IJavaElement> r, PropertyPredicate p) {
    JTableHeader header = (JTableHeader) component;
    TableColumnModel columnModel = header.getColumnModel();
    int col = columnModel.getColumnCount();
    for (int i = 0; i < col; i++) {
        JTableHeaderItemJavaElement e = new JTableHeaderItemJavaElement(this, i);
        if (p.isValid(e)) {
            r.add(e);
        }
    }
    return r;
}
 
public void populateTableHeaders() {

        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        final Calendar c = Calendar.getInstance();
        c.setTime(masterDate.getTime());

        JTableHeader tableHeader = table.getTableHeader();
        TableColumnModel tableColumnModel = tableHeader.getColumnModel();
        TableColumn tableColumn;

        tableColumn = tableColumnModel.getColumn(0);
        tableColumn.setHeaderValue("ROOM");
        tableColumn = tableColumnModel.getColumn(1);
        tableColumn.setHeaderValue("TYPE");
        tableColumn = tableColumnModel.getColumn(2);
        tableColumn.setHeaderValue("STATUS");

        //start the date from minus 1 to get today date.
        c.add(Calendar.DATE, -1);

        //start the loop from 3 because first 3 columns already 
        //populated up and the loop on 10 to get one week 
        for (int i = 3; i < 10; i++) {
            c.add(Calendar.DATE, 1);
            today = simpleDateFormat.format(c.getTime());
            tableColumn = tableColumnModel.getColumn(i);
            tableColumn.setHeaderValue(today);

            //store dates in special array to use it in bottom
            weekDates[i] = today;
        }

        tableHeader.revalidate();
        tableHeader.repaint();

    }
 
源代码19 项目: java-swing-tips   文件: MainPanel.java
@Override public void mousePressed(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  int idx = h.columnAtPoint(e.getPoint());
  if (idx < 0) {
    return;
  }
  TableColumnModel m = h.getColumnModel();
  Object title = m.getColumn(idx).getHeaderValue();
  cardLayout.show(contentsPanel, Objects.toString(title));
  selectedColumn = title;
}
 
源代码20 项目: netbeans   文件: TableSorter.java
@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);
    }
}