private void initTableVisualProperties(JTable table) {

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setIntercellSpacing(new java.awt.Dimension(0, 0));
    // set the color of the table's JViewport
    table.getParent().setBackground(table.getBackground());

    // we'll get the parents width so we can use that to set the column sizes.
    double pw = table.getParent().getParent().getPreferredSize().getWidth();

    // #88174 - Need horizontal scrollbar for library names
    // ugly but I didn't find a better way how to do it
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setMinWidth(226);
    column.setWidth(((int) pw / 2) - 1);
    column.setPreferredWidth(((int) pw / 2) - 1);
    column.setMinWidth(75);
    column = table.getColumnModel().getColumn(1);
    column.setMinWidth(226);
    column.setWidth(((int) pw / 2) - 1);
    column.setPreferredWidth(((int) pw / 2) - 1);
    column.setMinWidth(75);
    this.addComponentListener(new TableColumnSizeComponentAdapter(table));
  }
示例#2
0
 /**
  * カラムの非表示設定を行う.
  *
  * @param col 対象カラム番号
  * @param hide true:表示 false:非表示
  */
 public void setColumnHide(int col, boolean hide) {
   TableColumn tc = getColumnModel().getColumn(convertColumnIndexToView(col));
   int[] setting = new int[4];
   setting[0] = tc.getWidth();
   setting[1] = tc.getPreferredWidth();
   setting[2] = tc.getMinWidth();
   setting[3] = tc.getMaxWidth();
   if (hide) {
     if ((setting[0] == 0) && (setting[1] == 0) && (setting[2] == 0) && (setting[3] == 0)) {
       int[] baseSetting = columnSizeSetting.get(col);
       // setMaxWidthを実行する順番が大事
       tc.setMaxWidth(baseSetting[3]);
       tc.setMinWidth(baseSetting[2]);
       tc.setPreferredWidth(baseSetting[1]);
       tc.setWidth(baseSetting[0]);
     }
   } else {
     if ((setting[0] != 0) || (setting[1] != 0) || (setting[2] != 0) || (setting[3] != 0)) {
       columnSizeSetting.put(col, setting);
       // setMaxWidthを実行する順番が大事
       tc.setWidth(0);
       tc.setPreferredWidth(0);
       tc.setMinWidth(0);
       tc.setMaxWidth(0);
     }
   }
 }
  /**
   * Creates a new <code>TableColumnModel</code> along with its <code>TableColumn</code>s:
   * Selection, Name and Value columns.
   *
   * @return A new <code>TableColumnModel</code>
   */
  private TableColumnModel buildTableColumnModel() {
    DefaultTableColumnModel model = new DefaultTableColumnModel();

    // Selection column
    TableColumn selectionColumn = new TableColumn(PropertyColumnAdapter.SELECTION_COLUMN);
    selectionColumn.setCellRenderer(new SelectionTableCellRenderer());
    selectionColumn.setHeaderValue(" ");
    selectionColumn.setMaxWidth(20);
    selectionColumn.setMinWidth(20);
    selectionColumn.setPreferredWidth(20);
    selectionColumn.setResizable(false);
    model.addColumn(selectionColumn);

    // Name column
    TableColumn nameColumn = new TableColumn(PropertyColumnAdapter.NAME_COLUMN);
    nameColumn.setHeaderValue(resourceRepository().getString("LOGIN_PROPERTY_NAME_COLUMN"));
    nameColumn.setMinWidth(50);
    nameColumn.setResizable(true);
    model.addColumn(nameColumn);

    // Value column
    TableColumn valueColumn = new TableColumn(PropertyColumnAdapter.VALUE_COLUMN);
    valueColumn.setHeaderValue(resourceRepository().getString("LOGIN_PROPERTY_VALUE_COLUMN"));
    valueColumn.setMinWidth(50);
    valueColumn.setResizable(true);
    model.addColumn(valueColumn);

    return model;
  }
示例#4
0
  private void iniciarTabela() {

    tblCliente.setAutoCreateRowSorter(true);
    tblCliente.setRowHeight(35);

    TableColumn colunaDoc = tblCliente.getColumnModel().getColumn(DOCUMENTO);
    TableColumn colunaNome = tblCliente.getColumnModel().getColumn(NOME);
    TableColumn colunaEnd = tblCliente.getColumnModel().getColumn(ENDERECO);
    TableColumn colunaTel = tblCliente.getColumnModel().getColumn(TELEFONE);
    TableColumn colunaEdit = tblCliente.getColumnModel().getColumn(EDITAR);
    TableColumn colunaExcl = tblCliente.getColumnModel().getColumn(EXCLUIR);

    colunaDoc.setPreferredWidth(20);
    colunaNome.setPreferredWidth(200);
    colunaEnd.setPreferredWidth(200);
    colunaTel.setPreferredWidth(20);

    colunaEdit.setMaxWidth(50);
    colunaEdit.setMinWidth(35);
    colunaEdit.setCellRenderer(AbstractTableCrud.getIconCellRenderer());

    colunaExcl.setMaxWidth(50);
    colunaExcl.setMinWidth(35);
    colunaExcl.setCellRenderer(AbstractTableCrud.getIconCellRenderer());
  }
  private void fnHideColumn() {
    TableColumnModel tcm = this.tablePanel.getColumnModel();
    Object[] selected = this.cbList.getCheckBoxListSelectedValues();
    for (int i = 0; i < tcm.getColumnCount(); i++) {
      TableColumn tc = tcm.getColumn(i);
      String value = tc.getHeaderValue().toString();
      boolean matched = false;
      for (int j = 0; j < selected.length; j++) {
        if (value.equalsIgnoreCase(selected[j].toString())) {
          matched = true;
          break;
        }
      }
      if (!matched) {
        tc.setMinWidth(0);
        tc.setMaxWidth(0);
      } else {
        int width = this.model.getColumnWidth(value);
        tc.setMinWidth(width);

        tc.setWidth(width);
        tc.setPreferredWidth(width);
      }
    }
  }
 private boolean setColumnPreferredSize() {
   boolean sizeCalculated = false;
   Font tableFont = UIManager.getFont("Table.font");
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == GraphTableModel.ROOT_COLUMN) { // thin stripe, or root name, or nothing
       setRootColumnSize(column);
     } else if (i
         == GraphTableModel.COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i == GraphTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int maxWidth = 0;
       for (int row = 0; row < maxRowsToCheck; row++) {
         String value = getModel().getValueAt(row, i).toString();
         maxWidth = Math.max(getFontMetrics(tableFont).stringWidth(value), maxWidth);
         if (!value.isEmpty()) sizeCalculated = true;
       }
       column.setMinWidth(
           Math.min(maxWidth + UIUtil.DEFAULT_HGAP, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == GraphTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
   return sizeCalculated;
 }
示例#7
0
 private void setColumnPreferredSize() {
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing
       int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0;
       // NB: all further instructions and their order are important, otherwise the minimum size
       // which is less than 15 won't be applied
       column.setMinWidth(rootWidth);
       column.setMaxWidth(rootWidth);
       column.setPreferredWidth(rootWidth);
     } else if (i
         == AbstractVcsLogTableModel
             .COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i
         == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck);
       column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       Font tableFont = UIManager.getFont("Table.font");
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
 }
示例#8
0
 private void setColumnWidths() {
   if (!initialised) {
     return;
   }
   TableColumn checkCol = getColumnModel().getColumn(0);
   TableColumn descCol = getColumnModel().getColumn(1);
   TableColumn actCol = getColumnModel().getColumn(2);
   checkCol.setMinWidth(35);
   checkCol.setMaxWidth(35);
   checkCol.setWidth(30);
   int descWidth = getFontMetrics(getFont()).stringWidth(DESC_WIDTH_TEXT);
   descCol.setMinWidth(descWidth);
   descCol.setWidth(descWidth); // no maximum set, so it will stretch...
   actCol.setMinWidth(50);
   actCol.setMaxWidth(55);
   actCol.setWidth(55);
   /* and for advanced mode: */
   if (getColumnModel().getColumnCount() > 3) {
     descCol.setMinWidth(descWidth / 2);
     TableColumn prioCol = getColumnModel().getColumn(3);
     prioCol.setMinWidth(45);
     prioCol.setMaxWidth(50);
     prioCol.setWidth(50);
   }
 }
  /** Setzt die Breite der Spalten */
  public void setTableSize() {
    // Spaltenbreite der Checkboxen setzen
    TableColumn tc0 = table.getColumn(prakColumnNames[0]); // EventID
    TableColumn tc1 = table.getColumn(prakColumnNames[1]); // TutorID
    TableColumn tc2 = table.getColumn(prakColumnNames[2]); // Checkbox

    tc0.setMinWidth(0);
    tc0.setMaxWidth(0);
    tc1.setMinWidth(0);
    tc1.setMaxWidth(0);
    tc2.setMaxWidth(10);
    tc2.setMinWidth(10);
  }
  private void modificaTamanhoColuna() {
    TableColumn coluna = null;

    for (int i = 0; i < 5; i++) {
      coluna = getTabela().getColumnModel().getColumn(i);
      if (i == 1) {
        coluna.setPreferredWidth(100); // segunda coluna é a maior
        coluna.setMinWidth(20);
      } else {
        coluna.setPreferredWidth(50);
        coluna.setMinWidth(20);
      }
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see javax.swing.table.TableColumn#setMinWidth(int)
  */
 @Override
 public void setMinWidth(int minWidth) {
   // if ("Modul".equals(extColumn.getName())) {
   // System.out.println("set max");
   // }
   super.setMinWidth(minWidth);
 }
  /** function that creates History table */
  private void prepareUI() {
    for (int i = 0; i < 8; i++) {
      TableColumn column = tblTransactions.getColumnModel().getColumn(i);
      column.setHeaderRenderer(new PlainTableHeaderRenderer());
      if (i == 1 || i == 2) {
        column.setWidth(250);
        column.setMinWidth(250);
        column.setPreferredWidth(250);
      }
    }
    tblTransactions.getTableHeader().setFont(Fonts.DEFAULT_HEADING_FONT);
    tblTransactions.getTableHeader().setForeground(Color.BLACK);
    tblTransactions.getTableHeader().setBackground(Colors.TABLE_HEADER_BG_COLOR);
    tblTransactions.getTableHeader().setOpaque(true);

    scrollPane.setColumnHeader(
        new JViewport() {
          @Override
          public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.height = 25;
            return d;
          }
        });
    scrollPane.getHorizontalScrollBar().setUI(new XScrollbarUI());
    scrollPane.getVerticalScrollBar().setUI(new XScrollbarUI());
    tblTransactions.setRowHeight(25);
    tblTransactions.setDefaultRenderer(Object.class, new PlainTabelCellRenderer());
  }
  /** Creates a new instance of AbstractDatatypeTableColummModel */
  public AbstractDatatypeTableColummModel() {
    super();

    for (int i = 0; i < COLHEADS.length; ++i) {
      TableColumn col = new TableColumn(i, COLHEADWIDTHS[i]);
      col.setHeaderValue(COLHEADS[i]);
      col.setMinWidth(COLHEADWIDTHS[i]);
      addColumn(col);
    }

    this.setColumnSelectionAllowed(false);

    // this.addColumnModelListener( new TableColumnModelListener() {
    // public void columnSelectionChanged(ListSelectionEvent e) { }
    // public void columnMarginChanged(ChangeEvent e) {
    // System.out.println("COLUMN WIDTH  : "+
    // getColumn(0).getWidth()+" "+
    // getColumn(1).getWidth()+" "+
    // getColumn(2).getWidth()+" "+
    // getColumn(3).getWidth()+" "+
    // getColumn(4).getWidth());
    // }
    // public void columnRemoved(TableColumnModelEvent e) { }
    // public void columnAdded(TableColumnModelEvent e) { }
    // public void columnMoved(TableColumnModelEvent e) { }
    // });

  }
  private void prepareComponent() {
    CloseEventHandler closeEventHandler = new CloseEventHandler();
    addWindowListener(closeEventHandler);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    JPanel contentPanel = new JPanel();
    // JPanel contentPanel = new FormDebugPanel();
    contentPane.add(contentPanel, BorderLayout.CENTER);

    CellConstraints cc = new CellConstraints();
    FormLayout layout =
        new FormLayout(
            "4dlu, d:grow, 4dlu", // columns
            "4dlu, p, 2dlu, fill:100dlu:grow, 4dlu, "
                + // rows
                "p, 2dlu, p, 4dlu"); // btn rows
    PanelBuilder contentPB = new PanelBuilder(layout, contentPanel);
    int columnCount = layout.getColumnCount();
    int rowCount = layout.getRowCount();

    JLabel label = new JLabel(Localizer.getString("MediaTypeCondEditor_ConditionToAdd"));
    contentPB.add(label, cc.xywh(2, 2, 1, 1));

    mediaTypeModel = new MediaTypeModel();
    mediaTypeTable = new JTable(mediaTypeModel);
    JTableHeader tableHeader = mediaTypeTable.getTableHeader();
    tableHeader.setResizingAllowed(false);
    tableHeader.setReorderingAllowed(false);
    // adjust column witdh of checkbox
    JCheckBox box = (JCheckBox) mediaTypeTable.getDefaultRenderer(Boolean.class);
    TableColumn column = mediaTypeTable.getColumnModel().getColumn(0);
    column.setMaxWidth(box.getPreferredSize().width + 2);
    column.setMinWidth(box.getPreferredSize().width + 2);
    mediaTypeTable.getColumnModel().getColumn(1).setCellRenderer(new MediaTypeCellRenderer());
    // ToolTipManager.sharedInstance().registerComponent( mediaTypeTable );
    contentPB.add(new JScrollPane(mediaTypeTable), cc.xywh(2, 4, 1, 1));

    // button bar
    contentPB.add(new JSeparator(), cc.xywh(1, rowCount - 3, columnCount, 1));

    JButton okBtn = new JButton(Localizer.getString("OK"));
    okBtn.addActionListener(new OkBtnListener());
    okBtn.setDefaultCapable(true);
    okBtn.setRequestFocusEnabled(true);

    JButton cancelBtn = new JButton(Localizer.getString("Cancel"));
    cancelBtn.addActionListener(closeEventHandler);

    JPanel btnPanel = ButtonBarFactory.buildOKCancelBar(okBtn, cancelBtn);
    contentPB.add(btnPanel, cc.xywh(2, rowCount - 1, columnCount - 2, 1));

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    getRootPane().setDefaultButton(okBtn);

    pack();
    setLocationRelativeTo(getParent());
  }
示例#15
0
 // support ------------------------------------------------------------------------------------
 public static TableColumnModel getColumn(JTable table, int[] width) {
   TableColumnModel columns = table.getColumnModel();
   for (int i = 0; i < width.length; i++) {
     TableColumn column = columns.getColumn(i);
     column.setMinWidth(width[i]);
   }
   return columns;
 }
  public void init() {
    HierarchicalTableModel<P> tableModel = table.getModel();

    this.tableColumns.clear();

    if (tableModel == null) return;

    TableColumn column;

    int c = 0;

    if (tableModel.hasExpandableItems()) {
      Image minusImage = table.getStyle().getExpandedImage();
      Image plusImage = table.getStyle().getCollapsedImage();

      int w = minusImage.getWidth(null);
      column =
          new TableColumn(c++, w + 2, new ExpanderColumnCellRenderer(minusImage, plusImage), null);
      column.setMinWidth(w + 2);
      column.setMaxWidth(w + 2);
      column.setHeaderValue(tableModel.getColumnName(0));
      column.setResizable(false);

      addColumn(column);
    }

    if (tableModel.getKeyColumnWidth() >= 0) {
      int kcw = tableModel.getKeyColumnWidth();
      column = new TableColumn(c++, kcw, new KeyCellRenderer<P>(), null);
      column.setMinWidth(kcw);
      column.setMaxWidth(kcw);
      column.setResizable(false);
      column.setHeaderValue(tableModel.getColumnName(1));
      addColumn(column);
    } else {
      column = new TableColumn(c++, 20000, new KeyCellRenderer<P>(), null);
      // column = new TableColumn( c++, 20000, null, null );
      column.setHeaderValue(tableModel.getColumnName(1));
      addColumn(column);
    }

    // column = new TableColumn( c++, 20000, new StringKeyValueCellRenderer(), null );
    column = new TableColumn(c++, 20000, null, null);
    column.setHeaderValue(tableModel.getColumnName(2));
    addColumn(column);
  }
示例#17
0
  protected void addWidgets(DescriptorQueryList list, ActionMap actions, boolean captionsOnly) {
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder(caption));
    setBackground(AmbitColors.BrightClr);
    setForeground(AmbitColors.DarkClr);

    tableModel = new DescriptorQueryTableModel(list, captionsOnly);
    JTable table = new JTable(tableModel, createTableColumnModel(tableModel, captionsOnly));
    table.setSurrendersFocusOnKeystroke(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setRowSelectionAllowed(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowHeight(24);

    TableColumn col;

    int[] pSize = {32, 240, 32, 32, 64, 32, 32, 32};
    int[] mSize = {24, 120, 32, 32, 64, 32, 32, 32};
    for (int i = 0; i < table.getColumnCount(); i++) {
      col = table.getColumnModel().getColumn(i);
      col.setPreferredWidth(pSize[i]);
      col.setMinWidth(mSize[i]);
    }
    // table.setShowGrid(false);
    table.setShowHorizontalLines(true);
    table.setShowVerticalLines(false);

    scrollPane = new JScrollPane(table);
    scrollPane.setPreferredSize(new Dimension(420, 360));
    scrollPane.setMinimumSize(new Dimension(370, 120));
    scrollPane.setAutoscrolls(true);

    // tPane.addTab("Search descriptors",scrollPane);
    add(scrollPane, BorderLayout.CENTER);
    /*
    JToolBar t = new JToolBar();
    //t.setBackground(Color.white);
    t.setFloatable(false);
    //t.setBorder(BorderFactory.createTitledBorder("Search by descriptors and distance between atoms"));
    Object[] keys = actions.allKeys();
    if (keys != null) {
     for (int i=0; i < keys.length;i++)
     	t.add(actions.get(keys[i]));
     add(t,BorderLayout.SOUTH);
    }
    */
    if (actions != null) {
      Object[] keys = actions.allKeys();
      if (keys != null) {
        for (int i = 0; i < keys.length; i++) {
          add(
              new DescriptorSearchActionPanel(list, actions.get(keys[i]), keys[i].toString()),
              BorderLayout.SOUTH);
          break;
        }
      }
    }
  }
示例#18
0
 public JTable makePickTable() {
   JTable table = super.makePickTable();
   TableColumn column = new TableColumn(PickListModel.POSITION_COL);
   column.setResizable(true);
   column.setMinWidth(100);
   column.setHeaderValue("Logix");
   table.addColumn(column);
   return table;
 }
示例#19
0
  /**
   * Die Spalte verstecken.
   *
   * @param iColumnIndex der Index der Spalte
   * @param iColumnWidth doe absolute Breite der Spalte
   */
  private void setColumnWidthToZero(int iColumnIndex) {
    TableColumn tc = table.getColumnModel().getColumn(iColumnIndex);
    tc.setMinWidth(0);
    tc.setPreferredWidth(0);

    boolean showIIds = iColumnIndex == 0 && Defaults.getInstance().isShowIIdColumn();
    tc.setMaxWidth(showIIds ? Helper.getBreiteInPixel(QueryParameters.FLR_BREITE_M) : 0);
    tc.setResizable(showIIds);
  }
示例#20
0
 private void setTableColumnWidths() {
   table.sizeColumnsToFit(JTable.AUTO_RESIZE_NEXT_COLUMN);
   TableColumn column = null;
   column = table.getColumnModel().getColumn(0);
   column.setMinWidth(KEY_COL_WIDTH);
   column.setPreferredWidth(KEY_COL_WIDTH);
   column = table.getColumnModel().getColumn(1);
   column.setPreferredWidth(VAL_COL_WIDTH);
 }
  private void removeDefaultColumn(Outline o) {
    TableColumn nodeColumn = o.getColumnModel().getColumn(0);
    nodeColumn.setHeaderValue("");
    nodeColumn.setWidth(1);
    nodeColumn.setMaxWidth(1);
    nodeColumn.setMinWidth(1);
    //        o.getColumnModel().removeColumn(nodeColumn);

  }
 private void setFixedColumnWidth(final int columnIndex, String sampleText) {
   final TableColumn column =
       myEntryTable.getTableHeader().getColumnModel().getColumn(columnIndex);
   final FontMetrics fontMetrics = myEntryTable.getFontMetrics(myEntryTable.getFont());
   final int width = fontMetrics.stringWidth(" " + sampleText + " ") + JBUI.scale(4);
   column.setPreferredWidth(width);
   column.setMinWidth(width);
   column.setResizable(false);
 }
 public IdentityProviderAuditRecordTable() {
   super(createTableModel());
   TableColumn c = getColumn(RECORD);
   c.setMaxWidth(0);
   c.setMinWidth(0);
   c.setPreferredWidth(0);
   c.setResizable(false);
   this.clearTable();
 }
示例#24
0
 /** Initializes the table. */
 protected void init() {
   refreshTimer.setRepeats(false);
   refreshTimer.setCoalesce(true);
   setModel(rowModel);
   setColumnSelectionAllowed(true);
   setGridColor(Color.blue);
   setSelectionBackground(LIGHT_BLUE);
   setSelectionForeground(Color.red); // foreground color for selected cells
   setColumnModel(new DataTableColumnModel());
   setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
   setColumnSelectionAllowed(true);
   rowModel.addTableModelListener(
       new TableModelListener() {
         public void tableChanged(TableModelEvent e) {
           // forward the table model event to property change listeners
           DataRowTable.this.firePropertyChange("cell", null, e); // $NON-NLS-1$
         }
       });
   setDefaultRenderer(Object.class, cellRenderer);
   getTableHeader().setForeground(Color.blue); // set text color
   getTableHeader().setReorderingAllowed(true);
   getTableHeader().setDefaultRenderer(new HeaderRenderer());
   setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   int width = 24;
   String name;
   TableColumn column;
   if (getColumnCount() > 0) {
     // set width of column 0 (row index)
     name = getColumnName(0);
     column = getColumn(name);
     column.setMinWidth(width);
     column.setMaxWidth(2 * width);
     column.setWidth(width);
   }
   // set width of other columns
   width = 60;
   for (int i = 1, n = getColumnCount(); i < n; i++) {
     name = getColumnName(i);
     column = getColumn(name);
     column.setMinWidth(width);
     column.setMaxWidth(3 * width);
     column.setWidth(width);
   }
 }
 /** Sets the Table-Properties */
 private void setTableColumProperties() {
   ListTableCellRenderer renderer = new ListTableCellRenderer(mModel.getRowCount());
   int width = ListViewPlugin.PROGRAMTABLEWIDTH;
   for (int i = 0; i <= 2; i++) {
     TableColumn column = mProgramTable.getColumnModel().getColumn(i);
     column.setCellRenderer(renderer);
     if (i > 0) {
       column.setMinWidth(width);
     }
   }
 }
示例#26
0
  public static void setColumnWidth(
      JTable table, int columnIndex, int preferredWidth, int maxWidth, int minWidth) {
    TableColumn column = getTableColumn(table, columnIndex);
    if (column == null) {
      return;
    }

    column.setPreferredWidth(preferredWidth);
    column.setMaxWidth(maxWidth);
    column.setMinWidth(minWidth);
  }
示例#27
0
 private void setColumnWidth(int num, int minWidth, int maxWidth, int prefWidth) {
   TableColumn colum = compareTable.getColumnModel().getColumn(num);
   if (minWidth > 0) {
     colum.setMinWidth(minWidth);
   }
   if (maxWidth > 0) {
     colum.setMaxWidth(maxWidth);
   }
   if (prefWidth > 0) {
     colum.setPreferredWidth(prefWidth);
   }
 }
 /** Refresh the cell widths in the table. */
 public void refreshCellWidths() {
   // set width of columns
   for (int i = 0; i < getColumnCount(); i++) {
     String name = getColumnName(i);
     TableColumn statColumn = getColumn(name);
     name = dataTable.getColumnName(i);
     TableColumn dataColumn = dataTable.getColumn(name);
     statColumn.setMaxWidth(dataColumn.getWidth());
     statColumn.setMinWidth(dataColumn.getWidth());
     statColumn.setWidth(dataColumn.getWidth());
   }
 }
示例#29
0
  public ListPanel() {
    // TODO Auto-generated constructor stub
    this.setLayout(new GridBagLayout());
    GBC gbclist = new GBC(0, 0).setFill(GBC.BOTH).setWeight(100, 100);
    GBC gbcbar = new GBC(0, 1).setFill(GBC.HORIZONTAL).setWeight(100, 0);
    JTable list = new JTable();

    list.setAutoCreateRowSorter(true);
    ResultSet rs = null;
    try {
      rs = DbDao.getInstance().getStmt().executeQuery("select * from data");
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    model = new ResultSetTableModel(rs);
    list.setModel(model);

    TableColumnModel cmodel = list.getColumnModel();
    TableColumn tableurl = cmodel.getColumn(1);
    tableurl.setMinWidth(500);
    int[] arr = {0, 2, 3, 4, 5};
    for (int i : arr) {
      TableColumn column = cmodel.getColumn(i);
      column.setMinWidth(0);
      column.setMaxWidth(0);
    }
    JToolBar bar = new JToolBar();
    bar.setFloatable(false);
    status = new JLabel("完成");
    JScrollPane listPane = new JScrollPane(list);
    new ListPopMenu(this, listPane);
    new ListPopMenu(this, list);
    // listPane.setComponentPopupMenu(new ListPopMenu(this, listPane));
    // //swing弹出菜单,不需要awt监听事件。
    // list.setComponentPopupMenu(new ListPopMenu(this, list));
    this.add(listPane, gbclist);
    bar.add(status);
    this.add(bar, gbcbar);
  }
示例#30
0
  public static void loadPlayList(final String fileLocation) {
    try {
      System.out.println(fileLocation);
      table = TabelPanel.table;
      DefaultTableModel tableModel = TabelPanel.tableModel;
      final String datafile = fileLocation;
      final FileReader fin = new FileReader(datafile);

      tableModel = Csv2TableModel.createTableModel(fin, null);
      if (tableModel == null) {
        JOptionPane.showMessageDialog(
            null,
            "Error loading playlist, corrupted or unfinished.",
            "Error",
            JOptionPane.ERROR_MESSAGE);

        ModelUtils.loadPlayList("ta/scripts/blank.plist");
        PlayListPanel.canSetLast = false;
        return;
      } else {
        PlayListPanel.canSetLast = true;
      }
      table.setModel(tableModel);
      final TableColumn hiddenLink = table.getColumnModel().getColumn(LINK_INDEX);
      hiddenLink.setMinWidth(2);
      hiddenLink.setPreferredWidth(2);
      hiddenLink.setMaxWidth(2);
      hiddenLink.setCellRenderer(new InteractiveRenderer(LINK_INDEX));
      final TableColumn hiddenAlbumArt = table.getColumnModel().getColumn(ALBUMART_INDEX);
      hiddenAlbumArt.setMinWidth(2);
      hiddenAlbumArt.setPreferredWidth(2);
      hiddenAlbumArt.setMaxWidth(2);
      hiddenAlbumArt.setCellRenderer(new InteractiveRenderer(ALBUMART_INDEX));

    } catch (final FileNotFoundException e) {
      System.out.println("afaafvava");
      ModelUtils.loadPlayList("data/scripts/blank.plist");
    }
  }