Exemplo n.º 1
0
  /**
   * Luo tilikarttataulukon.
   *
   * @param container taulukon säiliö
   */
  private void createTable() {
    tableModel = new DocumentTypeTableModel();
    tableModel.setModel(model);

    table = new JTable(tableModel);
    table.setFillsViewportHeight(true);
    table.setPreferredScrollableViewportSize(new Dimension(400, 250));
    table.setRowHeight(24);

    TableColumn column;
    int[] widths = new int[] {80, 140, 80, 80};

    for (int i = 0; i < widths.length; i++) {
      column = table.getColumnModel().getColumn(i);
      column.setPreferredWidth(widths[i]);
    }

    /* Muutetaan enter-näppäimen toiminta. */
    table
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "nextCell");

    table.getActionMap().put("nextCell", nextCellAction);

    add(
        new JScrollPane(
            table,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
        BorderLayout.CENTER);
  }
Exemplo n.º 2
0
  /** Poistaa valitun vientimallin. */
  public void removeEntryTemplate() {
    int index = table.getSelectedRow();

    if (index < 0) {
      return;
    }

    model.removeDocumentType(index);
    tableModel.fireTableRowsDeleted(index, index);
    table.requestFocusInWindow();

    if (index >= 1) {
      table.setRowSelectionInterval(index - 1, index - 1);
    } else if (tableModel.getRowCount() > 0) {
      table.setRowSelectionInterval(0, 0);
    }
  }
Exemplo n.º 3
0
 /** Lisää vientimallin. */
 public void addEntryTemplate() {
   int index = model.addDocumentType();
   tableModel.fireTableRowsInserted(index, index);
   table.requestFocusInWindow();
   table.changeSelection(index, 1, false, false);
 }