Esempio n. 1
0
  private void initComponents() {
    {
      DefaultTableColumnModel model = new DefaultTableColumnModel();
      TableColumn column = new TableColumn(0);
      column.setResizable(true);
      model.addColumn(column);

      column = new TableColumn(1, 120, new ButtonCellRenderer(), null);
      column.setMaxWidth(120);
      column.setResizable(false);
      model.addColumn(column);

      companionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
      companionsTable.getTableHeader().setResizingAllowed(false);
      companionsTable.setAutoCreateColumnsFromModel(false);
      companionsTable.setColumnModel(model);
    }
    companionsTable.setIntercellSpacing(new Dimension(0, 0));
    companionsTable.setFocusable(false);
    companionsTable.setRowHeight(23);
    companionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setLeftComponent(new JScrollPane(companionsTable));
    JPanel rightPane = new JPanel(new BorderLayout());
    infoPane.setOpaque(false);
    infoPane.setEditable(false);
    infoPane.setFocusable(true);
    infoPane.setContentType("text/html"); // $NON-NLS-1$
    rightPane.add(new JScrollPane(infoPane), BorderLayout.CENTER);
    JPanel buttonPane = new JPanel(new FlowLayout());
    buttonPane.add(loadButton);
    rightPane.add(buttonPane, BorderLayout.SOUTH);
    setRightComponent(rightPane);
  }
  // listeners will receive columnAdded()/columnRemoved() event
  public void setColumnVisible(TableColumn column, boolean visible) {
    if (!visible) {
      super.removeColumn(column);
    } else {
      // find the visible index of the column:
      // iterate through both collections of visible and all columns, counting
      // visible columns up to the one that's about to be shown again
      int noVisibleColumns = tableColumns.size();
      int noInvisibleColumns = allTableColumns.size();
      int visibleIndex = 0;

      for (int invisibleIndex = 0; invisibleIndex < noInvisibleColumns; ++invisibleIndex) {
        TableColumn visibleColumn =
            (visibleIndex < noVisibleColumns ? (TableColumn) tableColumns.get(visibleIndex) : null);
        TableColumn testColumn = (TableColumn) allTableColumns.get(invisibleIndex);

        if (testColumn == column) {
          if (visibleColumn != column) {
            super.addColumn(column);
            super.moveColumn(tableColumns.size() - 1, visibleIndex);
          }
          return; // ####################
        }
        if (testColumn == visibleColumn) {
          ++visibleIndex;
        }
      }
    }
  }
Esempio n. 3
0
  /** Creates new form ValuesDialog */
  public StylesDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    applyI18n();
    this.setSize(490, 250);
    // DefaultTableColumnModel dtcm = (DefaultTableColumnModel)jTableParameters.getColumnModel();
    // DefaultTableCellRenderer tcr =
    // (DefaultTableCellRenderer)dtcm.getColumn(0).getHeaderRenderer();

    // new DefaultTableCellRenderer();
    // tcr.setFont(jTableParameters.getFont());
    // tcr.setBackground(this.getBackground());
    // tcr.setBorder( new javax.swing.border.BevelBorder( javax.swing.border.BevelBorder.RAISED));
    // dtcm.getColumn(0).setHeaderRenderer(tcr);

    DefaultListSelectionModel dlsm =
        (DefaultListSelectionModel) this.jTableParameters.getSelectionModel();
    dlsm.addListSelectionListener(
        new javax.swing.event.ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            jTableParametersListSelectionValueChanged(e);
          }
        });

    // Open in center...
    it.businesslogic.ireport.util.Misc.centerFrame(this);

    DefaultTableModel dtm = (DefaultTableModel) jTableParameters.getModel();

    it.businesslogic.ireport.gui.MainFrame.getMainInstance()
        .getActiveReportFrame()
        .getReport()
        .addStyleChangedListener(this);
    Enumeration e =
        it.businesslogic.ireport.gui.MainFrame.getMainInstance()
            .getActiveReportFrame()
            .getReport()
            .getStyles()
            .elements();
    while (e.hasMoreElements()) {
      Style style = (Style) e.nextElement();
      addStyle(style);
    }

    DefaultTableColumnModel dtcm = (DefaultTableColumnModel) jTableParameters.getColumnModel();
    dtcm.getColumn(0).setPreferredWidth(350);
    dtcm.getColumn(1).setPreferredWidth(100);

    javax.swing.KeyStroke escape =
        javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
    javax.swing.Action escapeAction =
        new javax.swing.AbstractAction() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
            setVisible(false);
          }
        };

    getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    getRootPane().getActionMap().put("ESCAPE", escapeAction);
  }
Esempio n. 4
0
 // 返回列的名称
 private String getSelectColumnIdentifier() {
   // 得到选中列索引
   int selectIndex = this.table.getSelectColumn();
   if (selectIndex == -1) return null;
   DefaultTableColumnModel colModel = (DefaultTableColumnModel) this.table.getColumnModel();
   return (String) colModel.getColumn(selectIndex).getIdentifier();
 }
  /**
   * 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;
  }
Esempio n. 6
0
  private void packColumns(int inMargin) {
    TableModel model = this.table.getModel();
    DefaultTableColumnModel columnModel = (DefaultTableColumnModel) table.getColumnModel();

    for (int col = 0; col < this.table.getColumnCount(); col++) {
      TableColumn column = columnModel.getColumn(col);

      int width = 0;

      // determine widest row in column
      for (int row = 0; row < this.table.getRowCount(); row++) {
        TableCellRenderer renderer = this.table.getCellRenderer(row, col);
        Component component =
            renderer.getTableCellRendererComponent(
                this.table, this.table.getValueAt(row, col), false, false, row, col);

        width = Math.max(width, component.getPreferredSize().width);
      }

      // add the margin
      width += 2 * inMargin;

      column.setPreferredWidth(width);
    }
  }
Esempio n. 7
0
  public void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;

    // Get width of column header
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
      renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp =
        renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;

    // Get maximum width of column data
    for (int r = 0; r < table.getRowCount(); r++) {
      renderer = table.getCellRenderer(r, vColIndex);
      comp =
          renderer.getTableCellRendererComponent(
              table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
      width = Math.max(width, comp.getPreferredSize().width);
    }

    // Add margin
    width += 2 * margin;

    // Set the width
    col.setPreferredWidth(width);
  }
Esempio n. 8
0
  private void packColumn(JTable table, int vColIndex, int margin) {
    //		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;

    // obtiene la anchura de la cabecera de la columna
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
      renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp =
        renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    //		width = comp.getPreferredSize().width;
    width = 5;

    // Obtine la anchura maxima de la coluna de
    for (int r = 0; r < table.getRowCount(); r++) {
      renderer = table.getCellRenderer(r, vColIndex);
      comp =
          renderer.getTableCellRendererComponent(
              table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
      width = Math.max(width, 0);
    }

    width += 2 * margin;

    // Configura el ancho
    col.setPreferredWidth(width);
  }
Esempio n. 9
0
 /**
  * Returns the table model with desired column attributes and header titles
  *
  * @return
  */
 private TableColumnModel getColumnModel() {
   DefaultTableColumnModel model = new DefaultTableColumnModel();
   TableColumn column1 = new TableColumn(0, 30);
   column1.setHeaderValue("#");
   TableColumn column2 = new TableColumn(1, 300);
   column2.setHeaderValue(Gui.lang.getString("branch"));
   TableColumn column3 = new TableColumn(2, 50);
   column3.setHeaderValue(Gui.lang.getString("abreviation"));
   model.addColumn(column1);
   model.addColumn(column2);
   model.addColumn(column3);
   return model;
 }
Esempio n. 10
0
  protected JTable createDefaultsTable() {
    JTable table = new JTable(new UIDefaultsTableModel());
    table.setRowHeight(rowHeight);
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    initFilters(table);

    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();

    Color rowColors[] = new Color[2];
    rowColors[0] = UIManager.getColor("Table.background");
    rowColors[1] =
        new Color(
            (int) (rowColors[0].getRed() * .90),
            (int) (rowColors[0].getGreen() * .95),
            (int) (rowColors[0].getBlue() * .95));

    int width = 0;

    TableColumn column = new TableColumn();
    column.setCellRenderer(new KeyRenderer(rowColors));
    column.setModelIndex(UIDefaultsTableModel.KEY_COLUMN);
    column.setHeaderValue("Key");
    column.setPreferredWidth(250);
    columnModel.addColumn(column);
    width += column.getPreferredWidth();

    column = new TableColumn();
    column.setCellRenderer(new RowRenderer(rowColors));
    column.setModelIndex(UIDefaultsTableModel.TYPE_COLUMN);
    column.setHeaderValue("Type");
    column.setPreferredWidth(250);
    columnModel.addColumn(column);
    width += column.getPreferredWidth();

    column = new TableColumn();
    column.setCellRenderer(new ValueRenderer(rowColors));
    column.setModelIndex(UIDefaultsTableModel.VALUE_COLUMN);
    column.setHeaderValue("Value");
    column.setPreferredWidth(300);
    columnModel.addColumn(column);
    width += column.getPreferredWidth();

    table.setColumnModel(columnModel);

    table.setPreferredScrollableViewportSize(new Dimension(width, 12 * rowHeight));

    return table;
  }
  /** Makes all columns in this model visible */
  public void setAllColumnsVisible() {
    int noColumns = allTableColumns.size();

    for (int columnIndex = 0; columnIndex < noColumns; ++columnIndex) {
      TableColumn visibleColumn =
          (columnIndex < tableColumns.size() ? (TableColumn) tableColumns.get(columnIndex) : null);
      TableColumn invisibleColumn = (TableColumn) allTableColumns.get(columnIndex);

      if (visibleColumn != invisibleColumn) {
        super.addColumn(invisibleColumn);
        super.moveColumn(tableColumns.size() - 1, columnIndex);
      }
    }
  }
Esempio n. 12
0
 // 设置每列的宽
 private void setTableColumn(JTable table) {
   DefaultTableColumnModel model = (DefaultTableColumnModel) table.getColumnModel();
   for (int i = 0; i < table.getColumnCount(); i++) {
     // 得到列对象
     TableColumn column = model.getColumn(i);
     // 得到列名
     String columnName = (String) column.getIdentifier();
     // 设置最小宽度
     int width = columnName.length() * 10;
     // 设置列宽最小为150
     int prefectWidth = (width < 150) ? 150 : width;
     column.setMinWidth(prefectWidth);
   }
 }
Esempio n. 13
0
  /**
   * Constructs a <code>VariabilityRecordTable</code> with a list of variability records.
   *
   * @param record_list the list of variability records.
   * @param desktop the parent desktop.
   */
  public VariabilityRecordTable(Vector record_list, net.aerith.misao.gui.Desktop desktop) {
    this.record_list = record_list;
    this.desktop = desktop;

    index = new ArrayIndex(record_list.size());

    model = new DefaultTableModel(column_names, 0);
    Object[] objects = new Object[column_names.length];
    objects[0] = new Boolean(true);
    for (int i = 1; i < column_names.length; i++) objects[i] = "";
    for (int i = 0; i < record_list.size(); i++) model.addRow(objects);
    setModel(model);

    column_model = (DefaultTableColumnModel) getColumnModel();
    for (int i = 1; i < column_names.length; i++)
      column_model
          .getColumn(i)
          .setCellRenderer(
              new StringRenderer(column_names[i], LabelTableCellRenderer.MODE_MULTIPLE_SELECTION));

    initializeCheckColumn();

    setTableHeader(new TableHeader(column_model));

    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    initializeColumnWidth();

    pane = this;

    initPopupMenu();
  }
 /**
  * Removes <code>column</code> from this column model. Posts <code>columnRemoved</code> event.
  * Will do nothing if the column is not in this model.
  *
  * @param column the column to be added
  * @see #addColumn
  */
 public void removeColumn(TableColumn column) {
   int allColumnsIndex = allTableColumns.indexOf(column);
   if (allColumnsIndex != -1) {
     allTableColumns.removeElementAt(allColumnsIndex);
   }
   super.removeColumn(column);
 }
  /**
   * Updates the column header component in the scroll pane. This depends on the current results
   * view and whether the sponsored results are visible.
   */
  private void syncColumnHeader() {
    Component resultHeader = resultsContainer.getScrollPaneHeader();
    if (resultHeader == null) {
      // If no headers, use nothing special.
      scrollPane.setColumnHeaderView(null);
    } else if (!sponsoredResultsPanel.isVisible()) {
      // If sponsored results aren't visible, just use the actual header.
      scrollPane.setColumnHeaderView(resultHeader);
    } else {
      // Otherwise, create a combined panel that has both sponsored results & header.
      JXPanel headerPanel = new JXPanel();
      // Make sure this syncs with the layout for the results & sponsored results!
      headerPanel.setLayout(new MigLayout("hidemode 3, gap 0, insets 0", "[]", "[grow][]"));
      headerPanel.add(resultHeader, "grow, push, alignx left, aligny top");

      DefaultTableColumnModel model = new DefaultTableColumnModel();
      TableColumn column = new TableColumn();
      model.addColumn(column);
      JTableHeader header = new JTableHeader(model);
      header.setDefaultRenderer(new TableCellHeaderRenderer());
      header.setReorderingAllowed(false);
      header.setResizingAllowed(false);
      header.setTable(new JXTable(0, 1));

      int width = sponsoredResultsPanel.getPreferredSize().width;
      int height = resultHeader.getPreferredSize().height;
      column.setWidth(width);
      Dimension dimension = new Dimension(width, height);
      header.setPreferredSize(dimension);
      header.setMaximumSize(dimension);
      header.setMinimumSize(dimension);

      headerPanel.add(header, "aligny top, alignx right");
      scrollPane.setColumnHeaderView(headerPanel);
    }

    scrollPane.validate();

    // Resize and repaint table header.  This eliminates visual issues due
    // to a change in the table format, which can result in an incorrect
    // header height or header flickering when a category is selected.
    if (resultHeader instanceof JTableHeader) {
      ((JTableHeader) resultHeader).resizeAndRepaint();
    }
  }
Esempio n. 16
0
  public void autoResizeColWidth() {

    int margin = 5;

    for (int i = 0; i < tabel.getColumnCount(); i++) {
      int vColIndex = i;
      DefaultTableColumnModel colModel = (DefaultTableColumnModel) tabel.getColumnModel();
      TableColumn col = colModel.getColumn(vColIndex);
      int width = 0;

      // Get width of column header
      TableCellRenderer renderer = col.getHeaderRenderer();

      if (renderer == null) {
        renderer = tabel.getTableHeader().getDefaultRenderer();
      }

      Component comp =
          renderer.getTableCellRendererComponent(tabel, col.getHeaderValue(), false, false, 0, 0);

      width = comp.getPreferredSize().width;

      // Get maximum width of column data
      for (int r = 0; r < tabel.getRowCount(); r++) {
        renderer = tabel.getCellRenderer(r, vColIndex);
        comp =
            renderer.getTableCellRendererComponent(
                tabel, tabel.getValueAt(r, vColIndex), false, false, r, vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
      }

      // Add margin
      width += 2 * margin;

      // Set the width
      col.setPreferredWidth(width);
    }

    ((DefaultTableCellRenderer) tabel.getTableHeader().getDefaultRenderer())
        .setHorizontalAlignment(SwingConstants.LEFT);

    // table.setAutoCreateRowSorter(true);
    tabel.getTableHeader().setReorderingAllowed(false);
  }
  /** Creates new form JInventoryLines */
  public JInventoryLines() {

    initComponents();

    DefaultTableColumnModel columns = new DefaultTableColumnModel();
    TableColumn c;

    c =
        new TableColumn(
            0,
            200,
            new DataCellRenderer(javax.swing.SwingConstants.LEFT),
            new DefaultCellEditor(new JTextField()));
    c.setHeaderValue(AppLocal.getIntString("label.item"));
    columns.addColumn(c);
    c =
        new TableColumn(
            1,
            75,
            new DataCellRenderer(javax.swing.SwingConstants.RIGHT),
            new DefaultCellEditor(new JTextField()));
    c.setHeaderValue(AppLocal.getIntString("label.units"));
    columns.addColumn(c);
    c =
        new TableColumn(
            2,
            75,
            new DataCellRenderer(javax.swing.SwingConstants.RIGHT),
            new DefaultCellEditor(new JTextField()));
    c.setHeaderValue(AppLocal.getIntString("label.price"));
    columns.addColumn(c);

    m_tableinventory.setColumnModel(columns);

    m_tableinventory.getTableHeader().setReorderingAllowed(false);
    m_tableinventory.setRowHeight(40);
    m_tableinventory.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_tableinventory.setIntercellSpacing(new java.awt.Dimension(0, 1));

    m_inventorylines = new InventoryTableModel();
    m_tableinventory.setModel(m_inventorylines);
  }
 public void packColumn(JTable table, int vColIndex, int margin) {
   TableModel model = table.getModel();
   DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
   TableColumn col = colModel.getColumn(vColIndex);
   int width = 0; // Obtém a largura do cabeçalho da coluna
   TableCellRenderer renderer = col.getHeaderRenderer();
   if (renderer == null) {
     renderer = table.getTableHeader().getDefaultRenderer();
   }
   Component comp =
       renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
   width = comp.getPreferredSize().width; // Obtém a largura maxima da coluna de dados
   for (int r = 0; r < table.getRowCount(); r++) {
     renderer = table.getCellRenderer(r, vColIndex);
     comp =
         renderer.getTableCellRendererComponent(
             table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
     width = Math.max(width, comp.getPreferredSize().width);
   }
   width += 2 * margin; // Configura a largura
   col.setPreferredWidth(width);
 }
Esempio n. 19
0
  public CharTable(Font font, FontEditor parent) {
    this.font = font;
    this.parent = parent;

    popup = new CharTablePopupMenu(this);

    columnModel = new DefaultTableColumnModel();

    TableColumn num = new TableColumn(0, 30);
    num.setHeaderValue("Dec");
    columnModel.addColumn(num);
    TableColumn hex = new TableColumn(1, 35);
    hex.setHeaderValue("Hex");
    columnModel.addColumn(hex);
    TableColumn ascii = new TableColumn(2, 37);
    ascii.setHeaderValue("ASCII");
    columnModel.addColumn(ascii);
    TableColumn width = new TableColumn(3, 37);
    width.setHeaderValue("Width");
    columnModel.addColumn(width);
    TableColumn desc = new TableColumn(4, 93);
    desc.setHeaderValue("Comment");
    columnModel.addColumn(desc);

    tableModel = new CharTableModel();
    tableModel.setColumnCount(5);

    charTable = new JTable(tableModel, columnModel);
    charTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    charTable.setMinimumSize(new Dimension(225, 100));
    charTable.addKeyListener(this);
    charTable.addMouseListener(this);
    charTable.addPropertyChangeListener(this);

    doRowData();
  }
Esempio n. 20
0
 /** Initializes the column width. */
 protected void initializeColumnWidth() {
   column_model.getColumn(0).setPreferredWidth(20);
   column_model.getColumn(1).setPreferredWidth(100);
   column_model.getColumn(2).setPreferredWidth(100);
   column_model.getColumn(3).setPreferredWidth(100);
   column_model.getColumn(4).setPreferredWidth(60);
   column_model.getColumn(5).setPreferredWidth(60);
   column_model.getColumn(6).setPreferredWidth(60);
   column_model.getColumn(7).setPreferredWidth(40);
   column_model.getColumn(8).setPreferredWidth(40);
   column_model.getColumn(9).setPreferredWidth(40);
   column_model.getColumn(10).setPreferredWidth(160);
   column_model.getColumn(11).setPreferredWidth(160);
 }
  /**
   * Moves the column from <code>oldIndex</code> to <code>newIndex</code>. Posts <code>columnMoved
   * </code> event. Will not move any columns if <code>oldIndex</code> equals <code>newIndex</code>.
   *
   * @param oldIndex index of column to be moved
   * @param newIndex new index of the column
   * @exception IllegalArgumentException if either <code>oldIndex</code> or <code>newIndex</code>
   *     are not in [0, getColumnCount() - 1]
   */
  public void moveColumn(int oldIndex, int newIndex) {
    if ((oldIndex < 0)
        || (oldIndex >= getColumnCount())
        || (newIndex < 0)
        || (newIndex >= getColumnCount()))
      throw new IllegalArgumentException("moveColumn() - Index out of range");

    TableColumn fromColumn = (TableColumn) tableColumns.get(oldIndex);
    TableColumn toColumn = (TableColumn) tableColumns.get(newIndex);

    int allColumnsOldIndex = allTableColumns.indexOf(fromColumn);
    int allColumnsNewIndex = allTableColumns.indexOf(toColumn);

    if (oldIndex != newIndex) {
      allTableColumns.removeElementAt(allColumnsOldIndex);
      allTableColumns.insertElementAt(fromColumn, allColumnsNewIndex);
    }

    super.moveColumn(oldIndex, newIndex);
  }
Esempio n. 22
0
  protected TableColumnModel createTableColumnModel(
      AbstractTableModel tableModel, boolean captionsOnly) {
    DefaultTableColumnModel cm = new DefaultTableColumnModel();
    TableColumn c = new TableColumn(0);
    c.setHeaderValue(tableModel.getColumnName(0));
    cm.addColumn(c);

    DefaultTableCellRenderer renderer =
        new DefaultTableCellRenderer() {

          public Component getTableCellRendererComponent(
              JTable table, Object arg1, boolean arg2, boolean arg3, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, arg1, arg2, arg3, row, column);
            Object o = table.getValueAt(row, column);
            setToolTipText(((DescriptorQuery) o).getRemark());
            return c;
          }
        };
    c = new TableColumn(1);
    c.setHeaderValue(tableModel.getColumnName(1));
    c.setCellRenderer(renderer);
    cm.addColumn(c);
    if (captionsOnly) return cm;

    TableColumn atom1Column = new TableColumn(2);
    atom1Column.setHeaderValue(tableModel.getColumnName(2));
    cm.addColumn(atom1Column);

    BorderCellRenderer brenderer = new BorderCellRenderer();
    brenderer.setToolTipText("Double click here to edit ");

    TableColumn atom2Column = new TableColumn(3);
    atom1Column.setHeaderValue(tableModel.getColumnName(3));
    cm.addColumn(atom2Column);
    JComboBox comboBox1 = new JComboBox();
    JComboBox comboBox2 = new JComboBox();

    String[] atoms = {"C", "N", "O", "P", "S", "Br", "Cl", "F", "I"};

    for (int i = 0; i < atoms.length; i++) {
      comboBox1.addItem(atoms[i]);
      comboBox2.addItem(atoms[i]);
    }
    atom1Column.setCellEditor(new DefaultCellEditor(comboBox1));
    atom2Column.setCellEditor(new DefaultCellEditor(comboBox2));

    TableColumn conditionColumn = new TableColumn(4);
    conditionColumn.setHeaderValue(tableModel.getColumnName(4));
    cm.addColumn(conditionColumn);
    JComboBox comboBox = new JComboBox();
    for (int i = 0; i < DescriptorQuery.conditions.length; i++)
      comboBox.addItem(DescriptorQuery.conditions[i]);
    conditionColumn.setCellEditor(new DefaultCellEditor(comboBox));

    renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click here ");
    conditionColumn.setCellRenderer(renderer);
    renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click here ");
    atom1Column.setCellRenderer(renderer);
    renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click here ");
    atom2Column.setCellRenderer(renderer);

    c = new TableColumn(5);
    c.setCellRenderer(brenderer);
    cm.addColumn(c);

    c = new TableColumn(6);
    cm.addColumn(c);

    c = new TableColumn(7);
    c.setCellRenderer(brenderer);
    cm.addColumn(c);

    return cm;
  }
Esempio n. 23
0
 public void removeColumn(TableColumn column) {
   super.removeColumn(column);
   renumberTableColumns();
 }
Esempio n. 24
0
 public void moveColumn(int columnIndex, int newIndex) {
   super.moveColumn(columnIndex, newIndex);
   renumberTableColumns();
 }
 @Override
 public void moveColumn(int from, int to) {
   super.moveColumn(from, from);
 }
 /**
  * Append <code>column</code> to the right of exisiting columns. Posts <code>columnAdded</code>
  * event.
  *
  * @param column The column to be added
  * @see #removeColumn
  * @exception IllegalArgumentException if <code>column</code> is <code>null</code>
  */
 public void addColumn(TableColumn column) {
   allTableColumns.addElement(column);
   super.addColumn(column);
 }