Package javax.swing.table

Examples of javax.swing.table.TableColumnModel


  /**
   * Updates table columns width from the content of its cells.
   */
  private void updateTableColumnsWidth() {
    int intercellWidth = getIntercellSpacing().width;
    TableColumnModel columnModel = getColumnModel();
    TableModel tableModel = getModel();
    for (int columnIndex = 0, n = columnModel.getColumnCount(); columnIndex < n; columnIndex++) {
      TableColumn column = columnModel.getColumn(columnIndex);
      int modelColumnIndex = convertColumnIndexToModel(columnIndex);
      int preferredWidth = column.getPreferredWidth();
      preferredWidth = Math.max(preferredWidth, column.getHeaderRenderer().getTableCellRendererComponent(
          this, column.getHeaderValue(), false, false, -1, columnIndex).getPreferredSize().width);
      for (int rowIndex = 0, m = tableModel.getRowCount(); rowIndex < m; rowIndex++) {
View Full Code Here


        final TableSorter sorter = this;
        final JTable tableView = table;
        tableView.setColumnSelectionAllowed(false);
        MouseAdapter listMouseListener = new MouseAdapter() {
            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) {
                    int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK;
                    boolean ascending = (shiftPressed == 0);
                    sorter.sortByColumn(column, ascending);
View Full Code Here

  }

  private class MouseHandler extends MouseAdapter {
    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();
        }
View Full Code Here

      properties.setValueAt(entry.getKey(), i, 0);
      properties.setValueAt(entry.getValue(), i, 1);
    }

    final JTable table = new JTable(properties);
    final TableColumnModel model = table.getColumnModel();
    TableColumn column = model.getColumn(0);
    column.setPreferredWidth(200);
    column = model.getColumn(1);
    column.setPreferredWidth(350);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    return table;
View Full Code Here

    tableView.getTableHeader().setDefaultRenderer(unSortedRenderer);
   
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {
      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) {
          if (singleSortingColumn == column)
            ascending = !ascending;
          else
            ascending = true;
          sorter.sortByColumn(column);
          singleSortingColumn = column;
         
          // setting renderer
          for (int i = 0; i < columnModel.getColumnCount(); i++)
            columnModel.getColumn(i).setHeaderRenderer(unSortedRenderer);
          if (ascending)
            sortedRenderer.setIconType(SortedTableHeaderRenderer.ASCENDING);
          else
            sortedRenderer.setIconType(SortedTableHeaderRenderer.DESCENDING);
          columnModel.getColumn(column).setHeaderRenderer(sortedRenderer);
        }
      }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
View Full Code Here

   *
   * @param user
   *            properties
   */
  public void setUserProperties(UserProperties up) {
    TableColumnModel tcm = table.getColumnModel();
    int nc = table.getModel().getColumnCount();
    TableColumn tl[] = new TableColumn[nc];
    int map[] = new int[nc];

    // get number of visible columns
    int ncv = up.getInt(propertiesPrefix+".logbookPanel.nbrColumn", nc);

    // remove all visible columns from the table
    for (int j = 0; j < nc; j++) {
      map[j] = -1;
      int l = table.convertColumnIndexToView(j);
      if (l >= 0) {
        tl[j] = tcm.getColumn(l);
        table.removeColumn(tl[j]);
      } else {
        tl[j] = null;
      }
    }
View Full Code Here

   *
   * @param user
   *            properties
   */
  public void getUserProperties(UserProperties up) {
    TableColumnModel tcm = table.getColumnModel();
    int ncv = tcm.getColumnCount();
    up.setInt(propertiesPrefix+".logbookPanel.nbrColumn", ncv);
    for (int j = 0; j < ncv; j++) {
      up.setInt(propertiesPrefix+".logbookPanel.columnIndex" + j, table
          .convertColumnIndexToModel(j));
      up.setInt(propertiesPrefix+".logbookPanel.columnSize" + j, tcm.getColumn(j)
          .getWidth());
    }
    up.setInt(propertiesPrefix+".logbookPanel.size", getLogbookModel().getSize());
  }
View Full Code Here

     */
    private class MouseHandler extends MouseAdapter {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = columnModel.getColumn(viewColumn).getModelIndex();
                if (column != -1) {
                    //We know we have clicked on a column.
                    //Show up a dialog to enter the new filter.
                    String newFilter = JOptionPane.showInputDialog("Enter filter for column "
                            + tableModel.getColumnName(column), filter[column]);
View Full Code Here

    JMTableColumn server_info_param_column = new JMTableColumn();
    server_info_param_column.setModelIndex(1);
    server_info_param_column.setHeaderValue(" ");
    server_info_param_column.setCellRenderer(new ServerInfoParamCellRenderer());
   
    TableColumnModel column_model = new DefaultTableColumnModel();
    column_model.addColumn(server_info_label_column);
    column_model.addColumn(server_info_param_column);
   
    this.setModel(new ServerInfoTableModel());
    this.setColumnModel(column_model);
  }
View Full Code Here

                  if( o1_order < o2_order ) return -1;
                  if( o1_order > o2_order ) return 1;
              return 0;
      }
    });   
    TableColumnModel column_model = new DefaultTableColumnModel();   
    for(TableColumnExt column : table_columns) {
      column_model.addColumn(column);
    }   
    column_model.setColumnMargin(0);
    this.setModel(tableModel);
    this.setColumnModel(column_model);
  }
View Full Code Here

TOP

Related Classes of javax.swing.table.TableColumnModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.