Example usage for javax.swing.table DefaultTableColumnModel DefaultTableColumnModel

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

Introduction

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

Prototype

public DefaultTableColumnModel() 

Source Link

Document

Creates a default table column model.

Usage

From source file:org.jdal.swing.ListTableModel.java

/**
 * Create a TableColumnModel for JTable. 
 * Try to use sizes and cell renderers from property descriptors.
 * @return a new TableColumnModel based on PropertyDescriptors
 */// w ww .  j  av a  2s.c  o  m
public TableColumnModel getTableColumnModel() {
    TableColumnModel tcm = new DefaultTableColumnModel();
    int baseIndex = 0;
    if (usingChecks) {
        TableColumn tableColumn = new TableColumn(0);
        tableColumn.setMaxWidth(50);
        tcm.addColumn(tableColumn);
        baseIndex++;
    }
    for (int i = 0; i < columnNames.size(); i++) {
        String name = this.columnNames.get(i);
        TableColumn tableColumn = new TableColumn(baseIndex + i);
        tableColumn.setHeaderValue(displayNames.get(i));

        if (pds != null && pds.size() > 0) {
            PropertyDescriptor descriptor = pds.get(i);
            // property values for TableColumns
            if (descriptor != null) {
                Integer maxWidth = getColumnWidth(name);
                if (maxWidth != null)
                    tableColumn.setMaxWidth(maxWidth.intValue());
                tableColumn.setCellRenderer(getColumnRenderer(name));
                tableColumn.setCellEditor(getColumnEditor(name));
            }
        }

        tcm.addColumn(tableColumn);
    }

    if (usingActions) {
        baseIndex += columnNames.size();
        for (int i = 0; i < actions.size(); i++) {
            TableColumn tableColumn = new TableColumn(baseIndex + i);
            tableColumn.setCellRenderer(new ActionCellRenderer());
            tableColumn.setMaxWidth(50);
            //   tableColumn.setCellEditor(new ActionCellEditor())
            tcm.addColumn(tableColumn);
        }
    }

    return tcm;
}

From source file:net.sf.taverna.t2.activities.spreadsheet.views.SpreadsheetImportConfigView.java

@Override
protected void initialise() {
    super.initialise();
    newConfiguration = getJson().deepCopy();

    // title//w w w.j  a v  a2  s  .  c om
    titlePanel = new JPanel(new BorderLayout());
    titlePanel.setBackground(Color.WHITE);
    addDivider(titlePanel, SwingConstants.BOTTOM, true);

    titleLabel = new JLabel(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.panelTitle"));
    titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 13.5f));
    titleIcon = new JLabel("");
    titleMessage = new DialogTextArea(DEFAULT_MESSAGE);
    titleMessage.setMargin(new Insets(5, 10, 10, 10));
    // titleMessage.setMinimumSize(new Dimension(0, 30));
    titleMessage.setFont(titleMessage.getFont().deriveFont(11f));
    titleMessage.setEditable(false);
    titleMessage.setFocusable(false);
    // titleMessage.setFont(titleLabel.getFont().deriveFont(Font.PLAIN,
    // 12f));

    // column range
    columnLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.columnSectionLabel"));

    JsonNode columnRange = newConfiguration.get("columnRange");
    columnFromValue = new JTextField(new UpperCaseDocument(),
            SpreadsheetUtils.getColumnLabel(columnRange.get("start").intValue()), 4);
    columnFromValue.setMinimumSize(columnFromValue.getPreferredSize());
    columnToValue = new JTextField(new UpperCaseDocument(),
            SpreadsheetUtils.getColumnLabel(columnRange.get("end").intValue()), 4);
    columnToValue.setMinimumSize(columnToValue.getPreferredSize());

    columnFromValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(columnFromValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(columnFromValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                addErrorMessage(EMPTY_FROM_COLUMN_ERROR_MESSAGE);
            } else if (text.trim().matches("[A-Za-z]+")) {
                String fromColumn = columnFromValue.getText().toUpperCase();
                String toColumn = columnToValue.getText().toUpperCase();
                int fromColumnIndex = SpreadsheetUtils.getColumnIndex(fromColumn);
                int toColumnIndex = SpreadsheetUtils.getColumnIndex(toColumn);
                if (checkColumnRange(fromColumnIndex, toColumnIndex)) {
                    columnMappingTableModel.setFromColumn(fromColumnIndex);
                    columnMappingTableModel.setToColumn(toColumnIndex);
                    newConfiguration.set("columnRange", newConfiguration.objectNode()
                            .put("start", fromColumnIndex).put("end", toColumnIndex));
                    validatePortNames();
                }
                removeErrorMessage(FROM_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_COLUMN_ERROR_MESSAGE);
            } else {
                addErrorMessage(FROM_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_COLUMN_ERROR_MESSAGE);
            }
        }

    });

    columnToValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(columnToValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(columnToValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                addErrorMessage(EMPTY_TO_COLUMN_ERROR_MESSAGE);
            } else if (text.trim().matches("[A-Za-z]+")) {
                String fromColumn = columnFromValue.getText().toUpperCase();
                String toColumn = columnToValue.getText().toUpperCase();
                int fromColumnIndex = SpreadsheetUtils.getColumnIndex(fromColumn);
                int toColumnIndex = SpreadsheetUtils.getColumnIndex(toColumn);
                if (checkColumnRange(fromColumnIndex, toColumnIndex)) {
                    columnMappingTableModel.setFromColumn(fromColumnIndex);
                    columnMappingTableModel.setToColumn(toColumnIndex);
                    newConfiguration.set("columnRange", newConfiguration.objectNode()
                            .put("start", fromColumnIndex).put("end", toColumnIndex));
                    validatePortNames();
                }
                removeErrorMessage(TO_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_TO_COLUMN_ERROR_MESSAGE);

            } else {
                addErrorMessage(TO_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_TO_COLUMN_ERROR_MESSAGE);
            }
        }
    });

    // row range
    rowLabel = new JLabel(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.rowSectionLabel"));
    addDivider(rowLabel, SwingConstants.TOP, false);

    rowSelectAllOption = new JCheckBox(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.selectAllRowsOption"));
    rowExcludeFirstOption = new JCheckBox(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.excludeHeaderRowOption"));
    rowIgnoreBlankRows = new JCheckBox(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.ignoreBlankRowsOption"));
    rowSelectAllOption.setFocusable(false);
    rowExcludeFirstOption.setFocusable(false);

    JsonNode rowRange = newConfiguration.get("rowRange");
    rowFromValue = new JTextField(new NumericDocument(), String.valueOf(rowRange.get("start").intValue() + 1),
            4);
    if (rowRange.get("end").intValue() == -1) {
        rowToValue = new JTextField(new NumericDocument(), "", 4);
    } else {
        rowToValue = new JTextField(new NumericDocument(), String.valueOf(rowRange.get("end").intValue() + 1),
                4);
    }
    rowFromValue.setMinimumSize(rowFromValue.getPreferredSize());
    rowToValue.setMinimumSize(rowToValue.getPreferredSize());

    if (newConfiguration.get("allRows").booleanValue()) {
        rowSelectAllOption.setSelected(true);
        rowFromValue.setEditable(false);
        rowFromValue.setEnabled(false);
        rowToValue.setEditable(false);
        rowToValue.setEnabled(false);
    } else {
        rowExcludeFirstOption.setEnabled(false);
    }
    rowExcludeFirstOption.setSelected(newConfiguration.get("excludeFirstRow").booleanValue());
    rowIgnoreBlankRows.setSelected(newConfiguration.get("ignoreBlankRows").booleanValue());

    rowFromValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(rowFromValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(rowFromValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                addErrorMessage(EMPTY_FROM_ROW_ERROR_MESSAGE);
            } else if (text.trim().matches("[1-9][0-9]*")) {
                checkRowRange(rowFromValue.getText(), rowToValue.getText());
                int fromRow = Integer.parseInt(rowFromValue.getText());
                ((ObjectNode) newConfiguration.get("rowRange")).put("start", fromRow - 1);
                removeErrorMessage(FROM_ROW_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_ROW_ERROR_MESSAGE);
            } else {
                addErrorMessage(FROM_ROW_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_ROW_ERROR_MESSAGE);
            }
        }
    });

    rowToValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(rowToValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(rowToValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                ((ObjectNode) newConfiguration.get("rowRange")).put("end", -1);
                removeErrorMessage(TO_ROW_ERROR_MESSAGE);
                removeErrorMessage(INCONSISTENT_ROW_MESSAGE);
            } else if (text.trim().matches("[0-9]+")) {
                checkRowRange(rowFromValue.getText(), rowToValue.getText());
                int toRow = Integer.parseInt(rowToValue.getText());
                ((ObjectNode) newConfiguration.get("rowRange")).put("end", toRow - 1);
                removeErrorMessage(TO_ROW_ERROR_MESSAGE);
            } else {
                addErrorMessage(TO_ROW_ERROR_MESSAGE);
            }
        }
    });

    rowSelectAllOption.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                newConfiguration.put("allRows", true);
                rowExcludeFirstOption.setEnabled(true);
                if (rowExcludeFirstOption.isSelected()) {
                    rowFromValue.setText("2");
                } else {
                    rowFromValue.setText("1");
                }
                rowToValue.setText("");
                rowFromValue.setEditable(false);
                rowFromValue.setEnabled(false);
                rowToValue.setEditable(false);
                rowToValue.setEnabled(false);
            } else {
                newConfiguration.put("allRows", false);
                rowExcludeFirstOption.setEnabled(false);
                rowFromValue.setEditable(true);
                rowFromValue.setEnabled(true);
                rowToValue.setEditable(true);
                rowToValue.setEnabled(true);
            }
        }
    });

    rowExcludeFirstOption.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                newConfiguration.put("excludeFirstRow", true);
                rowFromValue.setText("2");
                ((ObjectNode) newConfiguration.get("rowRange")).put("start", 1);
            } else {
                newConfiguration.put("excludeFirstRow", false);
                rowFromValue.setText("1");
                ((ObjectNode) newConfiguration.get("rowRange")).put("start", 0);
            }
        }
    });

    rowIgnoreBlankRows.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            newConfiguration.put("ignoreBlankRows", e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    // empty cells
    emptyCellLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.emptyCellSectionLabel"));
    addDivider(emptyCellLabel, SwingConstants.TOP, false);

    emptyCellButtonGroup = new ButtonGroup();
    emptyCellEmptyStringOption = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.emptyStringOption"));
    emptyCellUserDefinedOption = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.userDefinedOption"));
    emptyCellErrorValueOption = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.generateErrorOption"));
    emptyCellEmptyStringOption.setFocusable(false);
    emptyCellUserDefinedOption.setFocusable(false);
    emptyCellErrorValueOption.setFocusable(false);

    emptyCellUserDefinedValue = new JTextField(newConfiguration.get("emptyCellValue").textValue());

    emptyCellButtonGroup.add(emptyCellEmptyStringOption);
    emptyCellButtonGroup.add(emptyCellUserDefinedOption);
    emptyCellButtonGroup.add(emptyCellErrorValueOption);

    if (newConfiguration.get("emptyCellPolicy").textValue().equals("GENERATE_ERROR")) {
        emptyCellErrorValueOption.setSelected(true);
        emptyCellUserDefinedValue.setEnabled(false);
        emptyCellUserDefinedValue.setEditable(false);
    } else if (newConfiguration.get("emptyCellPolicy").textValue().equals("EMPTY_STRING")) {
        emptyCellEmptyStringOption.setSelected(true);
        emptyCellUserDefinedValue.setEnabled(false);
        emptyCellUserDefinedValue.setEditable(false);
    } else {
        emptyCellUserDefinedOption.setSelected(true);
        emptyCellUserDefinedValue.setText(newConfiguration.get("emptyCellValue").textValue());
        emptyCellUserDefinedValue.setEnabled(true);
        emptyCellUserDefinedValue.setEditable(true);
    }

    emptyCellEmptyStringOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newConfiguration.put("emptyCellPolicy", "EMPTY_STRING");
            emptyCellUserDefinedValue.setEnabled(false);
            emptyCellUserDefinedValue.setEditable(false);
        }
    });
    emptyCellUserDefinedOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newConfiguration.put("emptyCellPolicy", "USER_DEFINED");
            emptyCellUserDefinedValue.setEnabled(true);
            emptyCellUserDefinedValue.setEditable(true);
            emptyCellUserDefinedValue.requestFocusInWindow();
        }
    });
    emptyCellErrorValueOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newConfiguration.put("emptyCellPolicy", "GENERATE_ERROR");
            emptyCellUserDefinedValue.setEnabled(false);
            emptyCellUserDefinedValue.setEditable(false);
        }
    });

    emptyCellUserDefinedValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            newConfiguration.put("emptyCellValue", emptyCellUserDefinedValue.getText());
        }

        public void insertUpdate(DocumentEvent e) {
            newConfiguration.put("emptyCellValue", emptyCellUserDefinedValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            newConfiguration.put("emptyCellValue", emptyCellUserDefinedValue.getText());
        }
    });

    // column mappings
    columnMappingLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.columnMappingSectionLabel"));
    addDivider(columnMappingLabel, SwingConstants.TOP, false);

    Map<String, String> columnToPortMapping = new HashMap<>();
    if (newConfiguration.has("columnNames")) {
        for (JsonNode columnName : newConfiguration.get("columnNames")) {
            columnToPortMapping.put(columnName.get("column").textValue(), columnName.get("port").textValue());
        }
    }
    columnMappingTableModel = new SpreadsheetImportConfigTableModel(columnFromValue.getText(),
            columnToValue.getText(), columnToPortMapping);

    columnMappingTable = new JTable();
    columnMappingTable.setRowSelectionAllowed(false);
    columnMappingTable.getTableHeader().setReorderingAllowed(false);
    columnMappingTable.setGridColor(Color.LIGHT_GRAY);
    // columnMappingTable.setFocusable(false);

    columnMappingTable.setColumnModel(new DefaultTableColumnModel() {
        public TableColumn getColumn(int columnIndex) {
            TableColumn column = super.getColumn(columnIndex);
            if (columnIndex == 0) {
                column.setMaxWidth(100);
            }
            return column;
        }
    });

    TableCellEditor defaultEditor = columnMappingTable.getDefaultEditor(String.class);
    if (defaultEditor instanceof DefaultCellEditor) {
        DefaultCellEditor defaultCellEditor = (DefaultCellEditor) defaultEditor;
        defaultCellEditor.setClickCountToStart(1);
        Component editorComponent = defaultCellEditor.getComponent();
        if (editorComponent instanceof JTextComponent) {
            final JTextComponent textField = (JTextComponent) editorComponent;
            textField.getDocument().addDocumentListener(new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {
                    updateModel(textField.getText());
                }

                public void insertUpdate(DocumentEvent e) {
                    updateModel(textField.getText());
                }

                public void removeUpdate(DocumentEvent e) {
                    updateModel(textField.getText());
                }

                private void updateModel(String text) {
                    int row = columnMappingTable.getEditingRow();
                    int column = columnMappingTable.getEditingColumn();
                    columnMappingTableModel.setValueAt(text, row, column);

                    ArrayNode columnNames = newConfiguration.arrayNode();
                    Map<String, String> columnToPortMapping = columnMappingTableModel.getColumnToPortMapping();
                    for (Entry<String, String> entry : columnToPortMapping.entrySet()) {
                        columnNames.add(newConfiguration.objectNode().put("column", entry.getKey()).put("port",
                                entry.getValue()));
                    }
                    newConfiguration.put("columnNames", columnNames);
                    validatePortNames();
                }

            });
        }
    }

    columnMappingTable.setModel(columnMappingTableModel);

    // output format
    outputFormatLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.outputFormatSectionLabel"));

    outputFormatMultiplePort = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.multiplePortOption"));
    outputFormatSinglePort = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.singlePortOption"));
    outputFormatMultiplePort.setFocusable(false);
    outputFormatSinglePort.setFocusable(false);

    outputFormatDelimiterLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.userDefinedCsvDelimiter"));
    outputFormatDelimiter = new JTextField(newConfiguration.get("csvDelimiter").textValue(), 5);

    outputFormatButtonGroup = new ButtonGroup();
    outputFormatButtonGroup.add(outputFormatMultiplePort);
    outputFormatButtonGroup.add(outputFormatSinglePort);

    if (newConfiguration.get("outputFormat").textValue().equals("PORT_PER_COLUMN")) {
        outputFormatMultiplePort.setSelected(true);
        outputFormatDelimiterLabel.setEnabled(false);
        outputFormatDelimiter.setEnabled(false);
    } else {
        outputFormatSinglePort.setSelected(true);
        columnMappingLabel.setEnabled(false);
        enableTable(columnMappingTable, false);
    }

    outputFormatMultiplePort.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            outputFormatDelimiterLabel.setEnabled(false);
            outputFormatDelimiter.setEnabled(false);
            columnMappingLabel.setEnabled(true);
            enableTable(columnMappingTable, true);
            newConfiguration.put("outputFormat", "PORT_PER_COLUMN");
        }
    });
    outputFormatSinglePort.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            outputFormatDelimiterLabel.setEnabled(true);
            outputFormatDelimiter.setEnabled(true);
            columnMappingLabel.setEnabled(false);
            enableTable(columnMappingTable, false);
            newConfiguration.put("outputFormat", "SINGLE_PORT");
        }

    });
    outputFormatDelimiter.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            handleUpdate();
        }

        public void insertUpdate(DocumentEvent e) {
            handleUpdate();
        }

        public void removeUpdate(DocumentEvent e) {
            handleUpdate();
        }

        private void handleUpdate() {
            String text = null;
            try {
                text = StringEscapeUtils.unescapeJava(outputFormatDelimiter.getText());
            } catch (RuntimeException re) {
            }
            if (text == null || text.length() == 0) {
                newConfiguration.put("csvDelimiter", ",");
            } else {
                newConfiguration.put("csvDelimiter", text.substring(0, 1));
            }
        }

    });

    // buttons
    nextButton = new JButton(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.nextButton"));
    nextButton.setFocusable(false);
    nextButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            backButton.setVisible(true);
            nextButton.setVisible(false);
            cardLayout.last(contentPanel);
        }
    });

    backButton = new JButton(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.backButton"));
    backButton.setFocusable(false);
    backButton.setVisible(false);
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            nextButton.setVisible(true);
            backButton.setVisible(false);
            cardLayout.first(contentPanel);
        }
    });

    buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    addDivider(buttonPanel, SwingConstants.TOP, true);

    removeAll();
    layoutPanel();
}

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  ava 2  s . c  om
    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:pcgen.gui2.tabs.CompanionInfoTab.java

private void initComponents() {
    {//from  w ww.  j av a  2 s.com
        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);
}