Package javax.swing.table

Examples of javax.swing.table.TableColumnModel


    helpButton.addActionListener(new HelpAction(frame.helpDiag, GUIGlobals.importCustomizationHelp,
                                          "Help"));

    ImportTableModel tableModel = new ImportTableModel();
    customImporterTable = new JTable(tableModel);
    TableColumnModel cm = customImporterTable.getColumnModel();
    cm.getColumn(0).setPreferredWidth(GUIGlobals.IMPORT_DIALOG_COL_0_WIDTH);
    cm.getColumn(1).setPreferredWidth(GUIGlobals.IMPORT_DIALOG_COL_1_WIDTH);
    cm.getColumn(2).setPreferredWidth(GUIGlobals.IMPORT_DIALOG_COL_2_WIDTH);
    cm.getColumn(3).setPreferredWidth(GUIGlobals.IMPORT_DIALOG_COL_3_WIDTH);
    JScrollPane sp = new JScrollPane(customImporterTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                     JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    customImporterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    customImporterTable.setPreferredScrollableViewportSize(getSize());
    if (customImporterTable.getRowCount() > 0) {
View Full Code Here


    help.addActionListener(new HelpAction(frame.helpDiag, GUIGlobals.exportCustomizationHelp,
                                          "Help"));

    EventTableModel tableModel = new EventTableModel(Globals.prefs.customExports.getSortedList(), new ExportTableFormat());
    table = new JTable(tableModel);
    TableColumnModel cm = table.getColumnModel();
    cm.getColumn(0).setPreferredWidth(GUIGlobals.EXPORT_DIALOG_COL_0_WIDTH);
    cm.getColumn(1).setPreferredWidth(GUIGlobals.EXPORT_DIALOG_COL_1_WIDTH);
    cm.getColumn(2).setPreferredWidth(GUIGlobals.EXPORT_DIALOG_COL_2_WIDTH);
    JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                     JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setPreferredScrollableViewportSize(
      new Dimension(500, 150));
View Full Code Here

  /**
   * 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.getHeaderRenderer().getTableCellRendererComponent(
          this, column.getHeaderValue(), false, false, -1, columnIndex).getPreferredSize().width;
      int rowCount = tableModel.getRowCount();
      if (rowCount > 0) {
View Full Code Here

   */
  public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    // Create a printable column model from the column model of this table
    // with printable renderers for each column
    DefaultTableColumnModel printableColumnModel = new DefaultTableColumnModel();
    TableColumnModel columnModel = getColumnModel();
    final DefaultTableCellRenderer defaultRenderer = new DefaultTableCellRenderer();
    defaultRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
    TableCellRenderer printableHeaderRenderer = new TableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value,
                                   boolean isSelected, boolean hasFocus, int row, int column) {
          // Delegate rendering to default cell renderer
          JLabel headerRendererLabel = (JLabel)defaultRenderer.getTableCellRendererComponent(table, value,
              isSelected, hasFocus, row, column);
          // Don't display sort icon
          headerRendererLabel.setIcon(null);
          // Change header background and foreground
          headerRendererLabel.setBackground(Color.LIGHT_GRAY);
          headerRendererLabel.setForeground(Color.BLACK);
          headerRendererLabel.setBorder(BorderFactory.createCompoundBorder(
              BorderFactory.createLineBorder(Color.BLACK),
              headerRendererLabel.getBorder()));
          return headerRendererLabel;
        }
      };
    for (int columnIndex = 0, n = columnModel.getColumnCount(); columnIndex < n; columnIndex++) {
      final TableColumn tableColumn = columnModel.getColumn(columnIndex);
      // Create a printable column from existing table column
      TableColumn printableColumn = new TableColumn();
      printableColumn.setIdentifier(tableColumn.getIdentifier());
      printableColumn.setHeaderValue(tableColumn.getHeaderValue());
      TableCellRenderer printableCellRenderer = new TableCellRenderer() {
View Full Code Here

                    final PageFormat pageFormat,
                    final int pageIndex,
                    final TableColumnModel printableColumnModel,
                    final Color gridColor) throws PrinterException {
    if (EventQueue.isDispatchThread()) {
      TableColumnModel oldColumnModel = getColumnModel();
      Color oldGridColor = getGridColor();
      setColumnModel(printableColumnModel);  
      updateTableColumnsWidth();
      setGridColor(gridColor);
      Printable printable = getPrintable(PrintMode.FIT_WIDTH, null, null);
View Full Code Here

        }

        lModelTable.getTable().setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

        final BaseRenderer baseRenderer = new BaseRenderer();
        final TableColumnModel columnModel = lModelTable.getTable().getColumnModel();
        final RightAlignRenderer rightAlignRenderer = new RightAlignRenderer();
        int columnCounter = 0;
        mapCurrentColumntToPossibleColumn = new HashMap<Integer, Integer>();
       
        // Column "Enabled"
        columnModel.getColumn(columnCounter).setCellEditor(BooleanCell.EDITOR);
        setColumnEditable(columnCounter, true);
        columnModel.getColumn(columnCounter).setMinWidth(20);
        columnModel.getColumn(columnCounter).setMaxWidth(20);
        columnModel.getColumn(columnCounter).setPreferredWidth(20);
        columnModel.getColumn(columnCounter).setCellRenderer(new IsEnabledRenderer());
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.ENABLED.ordinal());

        if( fileSharingDisabled == false ) {
          // hard set sizes of icon column - Shared file
          columnModel.getColumn(columnCounter).setMinWidth(20);
          columnModel.getColumn(columnCounter).setMaxWidth(20);
          columnModel.getColumn(columnCounter).setPreferredWidth(20);
          columnModel.getColumn(columnCounter).setCellRenderer(new IsSharedRenderer());
          mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.SHARED_FILE.ordinal());
         
          // hard set sizes of icon column - File requested
          columnModel.getColumn(columnCounter).setMinWidth(20);
          columnModel.getColumn(columnCounter).setMaxWidth(20);
          columnModel.getColumn(columnCounter).setPreferredWidth(20);
          columnModel.getColumn(columnCounter).setCellRenderer(new IsRequestedRenderer());
          mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.FILE_REQUESTED.ordinal());
        }

        // fileName
        columnModel.getColumn(columnCounter).setCellRenderer(new ShowNameTooltipRenderer());
        columnModel.getColumn(columnCounter).setPreferredWidth(150);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.FILE_NAME.ordinal());
       
        // size
        columnModel.getColumn(columnCounter).setCellRenderer(rightAlignRenderer);
        columnModel.getColumn(columnCounter).setPreferredWidth(30);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.SIZE.ordinal());
       
        // state
        columnModel.getColumn(columnCounter).setCellRenderer(new ShowStateContentTooltipRenderer()); // state
        columnModel.getColumn(columnCounter).setPreferredWidth(30);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.STATE.ordinal());
       
        if( fileSharingDisabled == false ) {
          // lastSeen
          columnModel.getColumn(columnCounter).setCellRenderer(baseRenderer); // last
          columnModel.getColumn(columnCounter).setPreferredWidth(20);
          mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.LAST_SEEN.ordinal());
         
          // lastUloaded
          columnModel.getColumn(columnCounter).setCellRenderer(baseRenderer); // lastUploaded
          columnModel.getColumn(columnCounter).setPreferredWidth(20);
          mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.LAST_UPLOADED.ordinal());
        }
       
        // blocks
        columnModel.getColumn(columnCounter).setCellRenderer(new BlocksProgressRenderer()); // blocks
        columnModel.getColumn(columnCounter).setPreferredWidth(70);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.BLOCKS.ordinal());
       
        // tries
        columnModel.getColumn(columnCounter).setCellRenderer(rightAlignRenderer); // tries
        columnModel.getColumn(columnCounter).setPreferredWidth(10);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.TRIES.ordinal());
       
        // key
        columnModel.getColumn(columnCounter).setCellRenderer(new ShowContentTooltipRenderer()); // key
        columnModel.getColumn(columnCounter).setPreferredWidth(60);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.KEY.ordinal());
       
        // download dir
        columnModel.getColumn(columnCounter).setCellRenderer(baseRenderer); // download dir
        columnModel.getColumn(columnCounter).setPreferredWidth(60);
        mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.DOWNLOAD_DIRECTORY.ordinal());
       
        if( PersistenceManager.isPersistenceEnabled() ) {
          // IsDDA
          columnModel.getColumn(columnCounter).setMinWidth(20);
          columnModel.getColumn(columnCounter).setMaxWidth(20);
          columnModel.getColumn(columnCounter).setPreferredWidth(20);
            columnModel.getColumn(columnCounter).setCellRenderer(new IsDDARenderer());
            mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.DDA.ordinal());
           
            // priority
            columnModel.getColumn(columnCounter).setMinWidth(20);
            columnModel.getColumn(columnCounter).setMaxWidth(20);
            columnModel.getColumn(columnCounter).setPreferredWidth(20);
            columnModel.getColumn(columnCounter).setCellRenderer(rightAlignRenderer); // prio
            mapCurrentColumntToPossibleColumn.put(columnCounter++, Columns.PRIORITY.ordinal());
        }

        loadTableLayout(columnModel);
  }
View Full Code Here

        loadTableLayout(columnModel);
  }

    public void saveTableLayout() {
        final TableColumnModel tcm = modelTable.getTable().getColumnModel();
       
        for(int columnIndexInTable=0; columnIndexInTable < tcm.getColumnCount(); columnIndexInTable++) {
            final TableColumn tc = tcm.getColumn(columnIndexInTable);
            final int columnIndexInModel = tc.getModelIndex();
            final int columnIndexAll = mapCurrentColumntToPossibleColumn.get(columnIndexInModel);
           
            // save the current index in table for column with the fix index in model
            Core.frostSettings.setValue(CFGKEY_COLUMN_TABLEINDEX + columnIndexAll, columnIndexInTable);
View Full Code Here

      this.initHotKeyListener();
     
      addNewUploadsTable.setAutoResizeMode( JTable.AUTO_RESIZE_NEXT_COLUMN);
      int tableWidth = getWidth();
     
      TableColumnModel headerColumnModel = addNewUploadsTable.getTableHeader().getColumnModel();
      int defaultColumnWidthRatio[] = addNewUploadsTableModel.getDefaultColumnWidthRatio();
      for(int i = 0 ; i < defaultColumnWidthRatio.length ; i++) {
        headerColumnModel.getColumn(i).setMinWidth(5);
        int ratio = tableWidth * defaultColumnWidthRatio[i] /100;
        headerColumnModel.getColumn(i).setPreferredWidth(ratio);
      }
     
    } catch (final Exception e) {
      e.printStackTrace();
    }
View Full Code Here

        public void mouseClicked(MouseEvent event)
        {
            if( event.isPopupTrigger() == true )
                return; // dont allow right click sorts

            TableColumnModel colModel = getColumnModel();
            int index = colModel.getColumnIndexAtX(event.getX());
            int modelIndex = colModel.getColumn(index).getModelIndex();

            SortedTableModel<T> model = getModel();

            boolean isSortable = false;
            if( model != null && model.isSortable(modelIndex) )
View Full Code Here

     * charge of adding and removing the tablecolumn.
     */
private void createPopupMenu() {
        //Iterator it = mapTableColumnColumnKeeper.keySet().iterator();
        popupMenu = new JPopupMenu();
        TableColumnModel tcModel = this.getTable().getColumnModel();
        // int nbCol = tcModel.getColumnCount();

        //int nbCol = mapTableColumnColumnKeeper.keySet().size();
        for (Iterator entries = mapTableColumnColumnKeeper.entrySet().iterator(); entries.hasNext();) {
            // TableColumn column = tcModel.getColumn(i);
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.