Java 类javax.swing.table.TableColumnModel 实例源码

项目:Neukoelln_SER316    文件:TableSorter.java   
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); 
}
项目:parabuild-ci    文件: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);
            }
        }
项目:scorekeeperfrontend    文件:DriverTable.java   
@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 );
    }
}
项目:incubator-netbeans    文件:IssueTable.java   
@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());
}
项目:incubator-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();
        }
    }
}
项目:incubator-netbeans    文件:DiffTreeTable.java   
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();
}
项目:Cognizant-Intelligent-Test-Scripter    文件:TableCheckBoxColumn.java   
@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);
            }
        }
    }
}
项目:incubator-netbeans    文件:TaskListTable.java   
@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);
        }
    }
}
项目:incubator-netbeans    文件:TaskListTable.java   
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 );
}
项目:incubator-netbeans    文件:BookmarksView.java   
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
}
项目:scorekeeperfrontend    文件:Timer.java   
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);
    }
}
项目:incubator-netbeans    文件:SampledResultsPanel.java   
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]);
        }
    }
}
项目:s-store    文件: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);
            }
        }
项目:incubator-netbeans    文件:ReverseMemCallGraphPanel.java   
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]);
        }
    }
}
项目:incubator-netbeans    文件:LivenessResultsPanel.java   
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]);
        }
    }
}
项目:incubator-netbeans    文件:SubtreeCallGraphPanel.java   
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]);
        }
    }
}
项目:incubator-netbeans    文件:CCTDisplay.java   
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]);
        }
    }
}
项目:incubator-netbeans    文件:ProfilerTable.java   
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;
        }
    }
项目:incubator-netbeans    文件:JTreeTable.java   
public void updateTreeTableHeader() {
    TableColumnModel tableColumnModel = getColumnModel();
    int n = tableColumnModel.getColumnCount();

    for (int i = 0; i < n; i++) {
        tableColumnModel.getColumn(i).setHeaderRenderer(headerRenderer);
    }

    if (tableHeader != getTableHeader()) {
        if (tableHeader != null) {
            tableHeader.removeMouseListener(headerListener);
        }

        if (tableHeader != null) {
            tableHeader.removeMouseMotionListener(headerListener);
        }

        tableHeader = getTableHeader();
        tableHeader.addMouseListener(headerListener);
        tableHeader.addMouseMotionListener(headerListener);
        updateTreeTable();
    }
}
项目:dev-courses    文件: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);
            }
        }
项目:incubator-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);
    }
}
项目:incubator-netbeans    文件:DiffTreeTable.java   
@SuppressWarnings("unchecked")
private void setupColumns() {
    ResourceBundle loc = NbBundle.getBundle(DiffTreeTable.class);
    setPropertyColumns(RevisionNode.COLUMN_NAME_PATH, loc.getString("LBL_DiffTree_Column_Path"),
            RevisionNode.COLUMN_NAME_DATE, loc.getString("LBL_DiffTree_Column_Time"),
            RevisionNode.COLUMN_NAME_USERNAME, loc.getString("LBL_DiffTree_Column_Username"),
            RevisionNode.COLUMN_NAME_MESSAGE, loc.getString("LBL_DiffTree_Column_Message"));
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_PATH, loc.getString("LBL_DiffTree_Column_Path_Desc"));
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_DATE, loc.getString("LBL_DiffTree_Column_Time_Desc"));
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_USERNAME, loc.getString("LBL_DiffTree_Column_Username_Desc"));
    setPropertyColumnDescription(RevisionNode.COLUMN_NAME_MESSAGE, loc.getString("LBL_DiffTree_Column_Message_Desc"));
    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();
}
项目:scorekeeperfrontend    文件:QuickEntrySearch.java   
@Override
public void event(MT type, Object data)
{
    switch (type)
    {
        case QUICKID_SEARCH:
            if (getParent() instanceof JTabbedPane)
                ((JTabbedPane)getParent()).setSelectedComponent(this);
            entry.requestFocus();
        case EVENT_CHANGED:
        case ENTRANTS_CHANGED:
            cars.setRowSorter(null); // clear sorter so its listener based on old model size goes away
            cars.setModel(new EntryModel());
            TableColumnModel tcm = cars.getColumnModel();
            setColumnWidths(tcm.getColumn(0), 80, 160, 320);
            setColumnWidths(tcm.getColumn(1), 40, 80, 160);
            setColumnWidths(tcm.getColumn(2), 40, 80, 160);
            break;
    }
}
项目:rapidminer    文件:ExtendedJTableSorterModel.java   
@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();
    }
}
项目:openjdk-jdk10    文件:SortHeaderMouseAdapter.java   
public void mouseClicked(MouseEvent evt) {
    // XXX Benchmark sort performance
    //long start = System.currentTimeMillis();
    CommonUI.setWaitCursor(SwingUtilities.getRoot(table));

    TableColumnModel columnModel = table.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(evt.getX());
    int column = table.convertColumnIndexToModel(viewColumn);
    if (evt.getClickCount() == 1 && column != -1) {
        // Reverse the sorting direction.
        model.sortByColumn(column, !model.isAscending());
    }

    // XXX Benchmark performance
    //      System.out.println("Sort time: " +
    //         (System.currentTimeMillis() - start));
    CommonUI.setDefaultCursor(SwingUtilities.getRoot(table));
}
项目:rapidminer    文件:EditableTableHeader.java   
protected void recreateTableColumn(TableColumnModel columnModel) {
    int n = columnModel.getColumnCount();
    EditableTableHeaderColumn[] newCols = new EditableTableHeaderColumn[n];
    TableColumn[] oldCols = new TableColumn[n];
    for (int i = 0; i < n; i++) {
        oldCols[i] = columnModel.getColumn(i);
        newCols[i] = new EditableTableHeaderColumn(i);
        newCols[i].copyValues(oldCols[i]);
    }
    for (int i = 0; i < n; i++) {
        columnModel.removeColumn(oldCols[i]);
    }
    for (int i = 0; i < n; i++) {
        columnModel.addColumn(newCols[i]);
    }
}
项目:rapidminer    文件:EditableTableHeaderUI.java   
@Override
public void mousePressed(MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e)) {
        return;
    }
    super.mousePressed(e);

    if (header.getResizingColumn() == null) {
        Point p = e.getPoint();
        TableColumnModel columnModel = header.getColumnModel();
        int index = columnModel.getColumnIndexAtX(p.x);
        if (index != -1) {
            if (header.editCellAt(index, e)) {
                setDispatchComponent(e);
                repostEvent(e);
            }
        }
    }
}
项目:BadIntent    文件:ActiveAppView.java   
public ActiveAppView(Collection<AppInfo> activeApps) {
    this.activeApps = activeApps;

    setLayout(new BorderLayout());
    apps = new JTable();
    apps.setModel(new DefaultTableModel(0, 3));
    TableColumnModel columnModel = apps.getTableHeader().getColumnModel();
    columnModel.getColumn(0).setHeaderValue("Package");
    columnModel.getColumn(1).setHeaderValue("Interface");
    columnModel.getColumn(2).setHeaderValue("Port");

    panel.setLayout(new BorderLayout());
    panel.add(apps.getTableHeader(), BorderLayout.PAGE_START);
    panel.add(apps, BorderLayout.CENTER);
    panel.add(apps);

    scrollPane = new JScrollPane(panel);
    scrollPane.setVerticalScrollBar(scrollPane.createVerticalScrollBar());
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setViewportView(panel);

    add(scrollPane);

}
项目:Reinickendorf_SER316    文件:TableSorter.java   
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); 
}
项目:Cognizant-Intelligent-Test-Scripter    文件:JtableUtils.java   
/**
 * deletes all selected columns if it is not present in the <code>exp</code>
 * List
 *
 * @param table the table to DELETE columns
 * @param exp columns to avoid deleting
 * @see #deletecol(javax.swing.JTable, int)
 */
static void deletecols(JTable table, int[] exp) {
    Integer[] selcols;
    try {
        TableColumnModel tcm = table.getColumnModel();
        selcols = ArrayUtils.toObject(table.getSelectedColumns());
        Arrays.sort(selcols, Collections.reverseOrder());
        List<Integer> explist = Ints.asList(exp);
        for (int i : selcols) {
            if (!explist.contains(i)) {
                tcm.removeColumn(tcm.getColumn(i));
            }
        }

    } catch (Exception e) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, e);
    }

}
项目:jdk8u-jdk    文件:TableSorter.java   
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        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);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
项目:Course-Management-System    文件:CourseListPanel.java   
/**
 * Create the panel.
 */
public CourseListPanel(String user,ProfessorFrame pf) throws Exception{
    setLayout(new BorderLayout(0, 0));
       TableCellRenderer buttonRenderer = new ButtonRenderer();
    dao = new ProfessorDAO();
    model=new tableModelTeach(dao.getAllCourses(user),user,pf);
    table = new JTable();
    table.setRowHeight(30);

    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setDefaultRenderer(JButton.class,buttonRenderer);
    table.addMouseListener(new JTableButtonMouseListener(table));
    table.setModel(model);
    JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    //resizeColumnWidth(table);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableColumnModel tcm = table.getColumnModel();
    tcm.getColumn(0).setPreferredWidth(800);    
    tcm.getColumn(1).setPreferredWidth(200);    

    scrollPane.setBounds(10, 57, 1320, 450);
    add(scrollPane, BorderLayout.CENTER);
}
项目:openjdk-jdk10    文件:JTableHeaderOperator.java   
/**
 * Maps {@code JTableHeader.getColumnModel()} through queue
 */
public TableColumnModel getColumnModel() {
    return (runMapping(new MapAction<TableColumnModel>("getColumnModel") {
        @Override
        public TableColumnModel map() {
            return ((JTableHeader) getSource()).getColumnModel();
        }
    }));
}
项目:incubator-netbeans    文件:OutlineView.java   
private int getColumnXPos(OutlineViewOutline outline, int column) {
    if (column < 0) {
        if (!outline.getComponentOrientation().isLeftToRight()) {
            return outline.getWidth();
        } else {
            return 0;
        }
    } else if (column >= outline.getColumnCount()) {
        if (outline.getComponentOrientation().isLeftToRight()) {
            return outline.getWidth();
        } else {
            return 0;
        }
    } else {
        TableColumnModel cm = outline.getColumnModel();
        int x = 0;
        if (outline.getComponentOrientation().isLeftToRight()) {
            for (int i = 0; i < column; i++) {
                x += cm.getColumn(i).getWidth();
            }
        } else {
            for(int i = cm.getColumnCount()-1; i > column; i--) {
                x += cm.getColumn(i).getWidth();
            }
        }
        return x;
    }
}
项目:incubator-netbeans    文件:SheetTable.java   
/** Throws an UnsupportedOperationException when called by user code.  Replacing
 *  the column model of property sheets is unsupported.*/
@Override
public void setColumnModel(TableColumnModel model) {
    if (initialized) {
        throw new UnsupportedOperationException(
            "Changing the column model of a property sheet table is not supported.  If you want to change the set of properties, ordering or other characteristings, see setPropertySetModel()."
        ); //NOI18N
    }

    super.setColumnModel(model);
}
项目:incubator-netbeans    文件:OutlineViewOrderingTest.java   
public void testRemoveNodeColumn() throws InterruptedException, IllegalAccessException, InvocationTargetException {

        final TableColumnModel model = view.getOutline().getColumnModel();
        model.removeColumn(model.getColumn(0));
        assertEquals("One column visible", 1, model.getColumnCount());

        component.addNotify();
        final Node n0 = rootNode.getChildren().getNodeAt(0);

        rootNode.getChildren().remove(new Node[] { n0});
        assertEquals("One column visible after remove", 1, model.getColumnCount());
        rootNode.getChildren().add(new Node[] { n0});
        assertEquals("One column visible after add", 1, model.getColumnCount());
    }
项目:Cognizant-Intelligent-Test-Scripter    文件:TestsetComponent.java   
public StatusSorter() {
    testSetTable.getTableHeader().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            TableColumnModel columnModel = testSetTable.getColumnModel();
            int vci = columnModel.getColumnIndexAtX(me.getX());
            int mci = testSetTable.convertColumnIndexToModel(vci);
            if (mci == ExecutionStep.HEADERS.Status.getIndex()) {
                sort();
            }
        }
    });
}
项目:scorekeeperfrontend    文件:RunsTable.java   
public void setColumnSizes(TableColumnModelEvent e)
{
    TableColumnModel tcm = (TableColumnModel)e.getSource();
    for (int ii = 0; ii < tcm.getColumnCount(); ii++)
    {
        setColumnWidths(tcm.getColumn(ii), 70, 95, 200);
    }
    doLayout();
}
项目:incubator-netbeans    文件:VMOptionEditorPanel.java   
private void setUpColumns(TableColumnModel tcm, int start, int stop) {
    for (int i = start; i <= stop; i++) {
        final TableColumn column = tcm.getColumn(i);
        setUpColumn(column);
        if (i == 0) {
            column.setPreferredWidth(150);
            column.setMaxWidth(150);
        }
    }
}
项目:incubator-netbeans    文件:SyncTable.java   
void setDefaultColumnSizes() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            int width = table.getWidth();
            TableColumnModel cModel = table.getColumnModel();
            int columnCount = cModel.getColumnCount();
            if (tableColumns.length != columnCount) {
                return;
            }
            if (columnCount == 3) {
                for (int i = 0; i < columnCount; i++) {
                    if (SyncFileNode.COLUMN_NAME_PATH.equals(tableColumns[i])) {
                        cModel.getColumn(i).setPreferredWidth(width * 60 / 100);
                    } else {
                        cModel.getColumn(i).setPreferredWidth(width * 20 / 100);
                    }
                }
            } else if (columnCount == 4) {
                for (int i = 0; i < columnCount; i++) {
                    if (SyncFileNode.COLUMN_NAME_PATH.equals(tableColumns[i])) {
                        cModel.getColumn(i).setPreferredWidth(width * 55 / 100);
                    } else {
                        cModel.getColumn(i).setPreferredWidth(width * 15 / 100);
                    }
                }
            }
        }
    });
}