Example usage for javax.swing.table TableColumn TableColumn

List of usage examples for javax.swing.table TableColumn TableColumn

Introduction

In this page you can find the example usage for javax.swing.table TableColumn TableColumn.

Prototype

public TableColumn(int modelIndex) 

Source Link

Document

Cover method, using a default width of 75, a null renderer and a null editor.

Usage

From source file:v800_trainer.JCicloTronic.java

public void ChangeModel() {

    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    if (Hauptfenster != null)
        Hauptfenster.setSelectedIndex(0);
    DataProperty = new java.util.Properties();

    jTableaccess = Datentabelle;//from   ww  w  .  j  av a  2s . co  m
    String Filename = "";
    String PlaceHolder = "          ";
    File path = new File(Properties.getProperty("data.dir"));
    final String[] names = { "Datum", "Strecke", "Hhenmeter", "Zeit", "Titel" };

    String[] list = path.list(new DirFilter("_Tour.cfg"));

    RowCount = 0;
    int Anzahlcfg = 0;
    if (list != null)
        Anzahlcfg = list.length;
    if (Anzahlcfg == 0) {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        return;
    }

    Object datab[] = new Object[8];
    ArrayList<Object[]> data_list = new ArrayList<Object[]>();

    String hmString = "";
    DecimalFormat form = new DecimalFormat("0");//Format ohne Kommastelle
    int j = 0;
    for (int i = 0; i < Anzahlcfg; i++) { //berprfen ob Hhenmeter eingetragen sind - ansonsten ermitteln (gilt fr neue Dateien)
        Filename = path.getPath() + SystemProperties.getProperty("file.separator") + list[i];
        DataProperty = new java.util.Properties();
        try {

            BufferedInputStream in = new BufferedInputStream(new FileInputStream(Filename));
            DataProperty.load(in);
            in.close();
            // prfen ob Datei gezeigt werden soll - Visible = 0 wenn Datei gelscht wurde
            if (!DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1"))
                continue;
            // wenn keine Hhenmeter eingetragen wurden (Erstaufruf) dann Hhenmeter ermitteln
            if (DataProperty.getProperty("Hoehenmeter", "novalue").equalsIgnoreCase("novalue")
                    && DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1")
                    && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) {
                JTourData Dummydata = new JTourData(Filename.substring(0, Filename.lastIndexOf('.')), this);
                DataProperty.setProperty("Hoehenmeter", form.format(Dummydata.ges_Hoehep));
                try {
                    Ausgabedatei = new FileOutputStream(Filename);
                    DataProperty.store(Ausgabedatei,
                            "Tour Eigenschaften: " + DataProperty.getProperty("Jahr")
                                    + DataProperty.getProperty("Monat") + DataProperty.getProperty("Tag")
                                    + DataProperty.getProperty("Stunde") + DataProperty.getProperty("Minute"));
                    Ausgabedatei.close();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, " Fehler bei Speichern der DataProperty in ChangeModel",
                            "Achtung!", JOptionPane.ERROR_MESSAGE);

                }
            }

            try {
                if (Integer.parseInt(DataProperty.getProperty("Visible", "1")) == 1
                        && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) {

                    datab[0] = new String("  " + DataProperty.getProperty("Tag", "11") + "."
                            + DataProperty.getProperty("Monat", "11") + "."
                            + DataProperty.getProperty("Jahr", "1111"));
                    datab[1] = PlaceHolder.substring(0, 9 - DataProperty.getProperty("Strecke", "0").length())
                            + DataProperty.getProperty("Strecke", "0") + " ";
                    //                      data[j][1] = new String(DataProperty.getProperty("Strecke") + " ");
                    datab[2] = new String(
                            "  " + HMS(java.lang.Integer.parseInt(DataProperty.getProperty("Dauer", "0"))));
                    datab[3] = new String(DataProperty.getProperty("Titel", "---"));
                    datab[4] = new String(DataProperty.getProperty("Jahr", "1111") + "."
                            + DataProperty.getProperty("Monat", "11") + "."
                            + DataProperty.getProperty("Tag", "11") + "."
                            + DataProperty.getProperty("Stunde", "12") + "."
                            + DataProperty.getProperty("Minute", "59"));
                    datab[5] = new String(Filename.substring(0, Filename.lastIndexOf('.')));
                    datab[6] = new String(DataProperty.getProperty("Typ", "unbekannt"));
                    hmString = "" + (int) Float.parseFloat(DataProperty.getProperty("Hoehenmeter", "0"));
                    datab[7] = PlaceHolder.substring(0, 9 - hmString.length()) + hmString + " ";
                    data_list.add(datab.clone());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Fehler beim Erstellen der Datenliste " + e + " " + j,
                        "Achtung!", JOptionPane.ERROR_MESSAGE);
            }

        } catch (Exception e) {
            System.out.println(
                    "NEW IO-Fehler bei " + path.getPath() + SystemProperties.getProperty("file.separator")
                            + list[i] + "\n " + e + "   " + e.getLocalizedMessage() + "--File deleted");
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,
                    "Fehler beim Einlesen eines cfg Files " + path.getPath()
                            + SystemProperties.getProperty("file.separator") + list[i] + "\n  wurde gelscht!",
                    "Achtung!", JOptionPane.ERROR_MESSAGE);
            File deletefile = new File(
                    path.getPath() + SystemProperties.getProperty("file.separator") + list[i]);
            if (deletefile.exists())
                deletefile.delete();
            ChangeModel();
        }
    }

    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return names.length;
        }

        @Override
        public String getColumnName(int column) {
            return names[column];
        }

        @Override
        public int getRowCount() {
            return data_list.size();
        }

        @Override
        public Object getValueAt(int row, int col) {

            Object data[] = new Object[8];
            data = data_list.get(row);
            return data[col];
        }

        @Override
        public void setValueAt(Object Ob, int row, int col) {
            Object data[] = new Object[8];
            data = data_list.get(row);
            data[col] = Ob;
            data_list.set(row, data);

        }
    };

    sorter = new TableSorter(dataModel);
    DatumColumn = new TableColumn(0);
    DatumColumn.setHeaderValue(names[0]);
    DatumColumn.setResizable(false);
    StreckeColumn = new TableColumn(1);
    StreckeColumn.setHeaderValue(names[1]);
    StreckeColumn.setResizable(false);
    HoeheColumn = new TableColumn(7);
    HoeheColumn.setHeaderValue(names[2]);
    HoeheColumn.setResizable(false);
    ZeitColumn = new TableColumn(2);
    ZeitColumn.setHeaderValue(names[3]);
    ZeitColumn.setResizable(false);
    NotizColumn = new TableColumn(3);
    NotizColumn.setHeaderValue(names[4]);

    DatumColumn.setMinWidth((int) 80 * FontSize / 12);
    StreckeColumn.setMinWidth((int) 65 * FontSize / 12);
    HoeheColumn.setMinWidth((int) 75 * FontSize / 12);
    ZeitColumn.setMinWidth((int) 75 * FontSize / 12);
    NotizColumn.setMinWidth((int) 75 * FontSize / 12);
    NotizColumn.setPreferredWidth((int) 75 * FontSize / 12 + 1000);
    DefaultTableCellRenderer TableCell = new DefaultTableCellRenderer();
    TableCell.setHorizontalAlignment(JLabel.CENTER);
    HoeheColumn.setCellRenderer(TableCell);
    StreckeColumn.setCellRenderer(TableCell);
    DatumColumn.setCellRenderer(TableCell);
    ZeitColumn.setCellRenderer(TableCell);
    HoeheColumn.setHeaderRenderer(TableCell);
    StreckeColumn.setHeaderRenderer(TableCell);
    DatumColumn.setHeaderRenderer(TableCell);
    ZeitColumn.setHeaderRenderer(TableCell);
    NotizColumn.setHeaderRenderer(TableCell);

    DefaultTableColumnModel FileTableModel = new DefaultTableColumnModel();
    FileTableModel.addColumn(DatumColumn);
    FileTableModel.addColumn(StreckeColumn);
    FileTableModel.addColumn(HoeheColumn);
    FileTableModel.addColumn(ZeitColumn);
    FileTableModel.addColumn(NotizColumn);

    Datentabelle.setModel(sorter);
    Datentabelle.setColumnModel(FileTableModel);
    Datentabelle.setRowHeight(FontSize + 5);
    sorter.addMouseListenerToHeaderInTable(Datentabelle);
    sorter.sortByColumn(0, false);
    Datentabelle.clearSelection();
    SelectionChanged = true;

    JScrollBar verticaldummy = Datenliste_scroll_Panel.getVerticalScrollBar();

    verticaldummy.setPreferredSize(new Dimension(FontSize + 10, FontSize + 10));
    Datenliste_scroll_Panel.setVerticalScrollBar(verticaldummy);

    Update = false;
    Datenliste_Jahr.removeAllItems();
    Datenliste_TourTyp.removeAllItems();
    Auswahl_bersicht.removeAllItems();
    JahrVergleich.removeAllItems();

    InitComboJahr();
    InitComboTyp();

    Update = true;

    if (Datentabelle.getRowCount() != 0) {
        Datentabelle.addRowSelectionInterval(0, 0);
        Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0));
    }

    if (Uebersicht != null) {
        Uebersicht = null;
    }
    jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount());

    repaint();
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

public boolean addColumn() {
    DefaultTableModel model = (DefaultTableModel) scrollTable.getModel();
    TableColumn col = new TableColumn(scrollTable.getModel().getColumnCount());
    col.setHeaderRenderer(scrollTableHeaderRenderer);

    SpreadsheetUtils.stopCellEditingInTable(scrollTable);

    return doAddColumn(model, col);
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Adds a column to the table with a specified name
 *
 * @param headerLabel - name of column to be added
 *//*  w  ww  . ja  v a 2s.  c o m*/
public TableColumn addColumn(Object headerLabel, boolean required) {
    SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();
    TableColumn newColumn = new TableColumn(spreadsheet.getTable().getModel().getColumnCount());
    newColumn.setHeaderValue(headerLabel);
    newColumn.setPreferredWidth(calcColWidths(headerLabel.toString()));
    newColumn.setHeaderRenderer(spreadsheet.columnRenderer);

    // add a cell editor (if available to the column)
    addCellEditor(newColumn);

    model.addToColumns(headerLabel.toString());
    model.addColumn(headerLabel.toString());

    spreadsheet.getTable().addColumn(newColumn);

    addFieldToRequiredCellRendererIfVisible(required, newColumn.getModelIndex());

    model.fireTableStructureChanged();
    model.fireTableDataChanged();

    if (spreadsheet.getTable().getRowCount() > 0) {
        spreadsheet.getTable().setValueAt(
                spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()), 0,
                spreadsheet.getTable().getColumnCount() - 1);
        copyColumnDownwards(0, spreadsheet.getTable().getColumnCount() - 1);
        spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString());
    }

    spreadsheet.getTable().addNotify();

    return newColumn;
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Add a column after the currently selected column
 *
 * @param headerLabel             - name of column to add.
 * @param fixedVal                - initial value to populate column with, if any.
 * @param currentlySelectedColumn - place in table to add the column after.
 *//*from  ww w .j  av a2  s  .c  o  m*/
public TableColumn addColumnAfterPosition(Object headerLabel, String fixedVal, boolean required,
        int currentlySelectedColumn) {

    if (currentlySelectedColumn == -1) {
        currentlySelectedColumn = (spreadsheet.getTable().getSelectedColumn() == -1)
                ? (spreadsheet.getTable().getColumnCount() - 1)
                : spreadsheet.getTable().getSelectedColumn();
    }

    SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();

    int columnCount = spreadsheet.getTable().getModel().getColumnCount();

    TableColumn col = new TableColumn(columnCount);
    col.setHeaderValue(headerLabel);
    col.setPreferredWidth(calcColWidths(headerLabel.toString()));
    col.setHeaderRenderer(spreadsheet.columnRenderer);

    addFieldToRequiredCellRendererIfVisible(required, columnCount);

    addCellEditor(col);

    model.addToColumns(headerLabel.toString());
    model.addColumn(col);

    spreadsheet.getTable().addColumn(col);

    model.fireTableStructureChanged();
    model.fireTableDataChanged();

    // now move the column into its correct position
    int stopValue = headerLabel.toString().equals("Unit")
            ? (spreadsheet.previouslyAddedCharacteristicPosition + 1)
            : (currentlySelectedColumn + 1);

    for (int i = spreadsheet.getTable().getColumnCount() - 1; i > stopValue; i--) {
        spreadsheet.getTable().getColumnModel().moveColumn(i - 1, i);
    }

    addDependentColumn(headerLabel, currentlySelectedColumn, col);

    if (headerLabel.toString().contains("Characteristics") || headerLabel.toString().contains("Factor")
            || headerLabel.toString().contains("Parameter")) {
        spreadsheet.previouslyAddedCharacteristicPosition = stopValue;
    }

    propagateDefaultValue(fixedVal, stopValue);

    spreadsheet.getTable().addNotify();

    return col;
}

From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java

/**
 * Creates default columns for the table from the data model using the <code>getColumnCount</code> method defined in
 * the <code>TableModel</code> interface.
 * <p/>/*  w w  w  .j  av a 2  s .c o  m*/
 * Clears any existing columns before creating the new columns based on information from the model.
 *
 * @see #getAutoCreateColumnsFromModel
 */
public void createDefaultColumnsFromModel() {
    final TableModel m = getModel();
    if (m != null) {
        // Remove any current columns
        final TableColumnModel cm = getColumnModel();
        while (cm.getColumnCount() > 0) {
            cm.removeColumn(cm.getColumn(0));
        }

        // Create new columns from the data model info
        for (int i = 0; i < m.getColumnCount(); i++) {
            if (i == 0) {
                final TableColumn column = new TableColumn(i);
                column.setCellRenderer(tableHeader.getDefaultRenderer());
                addColumn(column);
                continue;
            }

            final EditableHeaderTableColumn newColumn = new EditableHeaderTableColumn(i);
            newColumn.setHeaderEditor(new TypedHeaderCellEditor());
            addColumn(newColumn);
        }
    }
}

From source file:pcgen.gui2.tabs.CompanionInfoTab.java

private void initComponents() {
    {//from w ww  .  ja  v  a2 s. c o  m
        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);
}

From source file:pcgen.gui2.tabs.EquipInfoTab.java

private DynamicTableColumnModel createEquipmentColumnModel() {
    PrefTableColumnModel model = new PrefTableColumnModel("EquipList", 1);

    TableColumn column = new TableColumn(0);
    column.setHeaderValue(LanguageBundle.getString("in_nameLabel")); //$NON-NLS-1$
    model.addColumn(column, true, 150);//from  ww w  .  j av a 2 s. c  om
    column = new TableColumn(1);
    column.setHeaderValue(LanguageBundle.getString("in_type")); //$NON-NLS-1$
    model.addColumn(column, true, 75);
    column = new TableColumn(2);
    column.setHeaderValue(LanguageBundle.getString("in_equipLocationAbbrev")); //$NON-NLS-1$
    model.addColumn(column, true, 75);
    column = new TableColumn(3);
    column.setHeaderValue(LanguageBundle.getString("in_equipQuantityAbbrev")); //$NON-NLS-1$
    model.addColumn(column, true, 75);
    column = new TableColumn(4);
    column.setHeaderValue(LanguageBundle.getString("in_equipWeightAbbrev")); //$NON-NLS-1$
    model.addColumn(column, true, 75);
    column = new TableColumn(5);
    column.setHeaderValue(LanguageBundle.getString("in_descrip")); //$NON-NLS-1$
    model.addColumn(column, false, 75);
    return model;
}