Example usage for javax.swing.table AbstractTableModel AbstractTableModel

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

Introduction

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

Prototype

AbstractTableModel

Source Link

Usage

From source file:MainClass.java

public MainClass() {
    super("Selection Model Test");
    setSize(450, 350);//from ww  w. j  a  v  a  2 s  .  c  o  m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        public int getRowCount() {
            return 10;
        }

        public int getColumnCount() {
            return 10;
        }

        public Object getValueAt(int r, int c) {
            return "0";
        }
    };

    final JTable jt = new JTable(tm);

    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);

    JPanel controlPanel, buttonPanel, columnPanel, rowPanel;

    buttonPanel = new JPanel();
    final JCheckBox cellBox, columnBox, rowBox;
    cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled());
    columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed());
    rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed());

    cellBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setCellSelectionEnabled(cellBox.isSelected());
            columnBox.setSelected(jt.getColumnSelectionAllowed());
            rowBox.setSelected(jt.getRowSelectionAllowed());
        }
    });

    columnBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setColumnSelectionAllowed(columnBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    rowBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setRowSelectionAllowed(rowBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    buttonPanel.add(new JLabel("Selections allowed:"));
    buttonPanel.add(cellBox);
    buttonPanel.add(columnBox);
    buttonPanel.add(rowBox);

    columnPanel = new JPanel();
    ListSelectionModel csm = jt.getColumnModel().getSelectionModel();
    JLabel columnCounter = new JLabel("Selected Column Indices:");
    csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm));
    columnPanel.add(new JLabel("Selected columns:"));
    columnPanel.add(columnCounter);

    rowPanel = new JPanel();
    ListSelectionModel rsm = jt.getSelectionModel();
    JLabel rowCounter = new JLabel("Selected Row Indices:");
    rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm));
    rowPanel.add(new JLabel("Selected rows:"));
    rowPanel.add(rowCounter);

    controlPanel = new JPanel(new GridLayout(0, 1));
    controlPanel.add(buttonPanel);
    controlPanel.add(columnPanel);
    controlPanel.add(rowPanel);

    getContentPane().add(controlPanel, BorderLayout.SOUTH);
}

From source file:RowHeaderTable.java

public RowHeaderTable() {
    super("Row Header Test");
    setSize(300, 200);//from w  w w.  ja  v  a 2  s  . c om
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        String data[] = { "", "a", "b", "c", "d", "e" };

        String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" };

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

        public int getRowCount() {
            return 1000;
        }

        public String getColumnName(int col) {
            return headers[col];
        }

        // Synthesize some entries using the data values & the row #
        public Object getValueAt(int row, int col) {
            return data[col] + row;
        }
    };

    // Create a column model for the main table. This model ignores the
    // first
    // column added, and sets a minimum width of 150 pixels for all others.
    TableColumnModel cm = new DefaultTableColumnModel() {
        boolean first = true;

        public void addColumn(TableColumn tc) {
            // Drop the first column . . . that'll be the row header
            if (first) {
                first = false;
                return;
            }
            tc.setMinWidth(150); // just for looks, really...
            super.addColumn(tc);
        }
    };

    // Create a column model that will serve as our row header table. This
    // model picks a maximum width and only stores the first column.
    TableColumnModel rowHeaderModel = new DefaultTableColumnModel() {
        boolean first = true;

        public void addColumn(TableColumn tc) {
            if (first) {
                tc.setMaxWidth(tc.getPreferredWidth());
                super.addColumn(tc);
                first = false;
            }
            // Drop the rest of the columns . . . this is the header column
            // only
        }
    };

    JTable jt = new JTable(tm, cm);

    // Set up the header column and get it hooked up to everything
    JTable headerColumn = new JTable(tm, rowHeaderModel);
    jt.createDefaultColumnsFromModel();
    headerColumn.createDefaultColumnsFromModel();

    // Make sure that selections between the main table and the header stay
    // in sync (by sharing the same model)
    jt.setSelectionModel(headerColumn.getSelectionModel());

    // Make the header column look pretty
    //headerColumn.setBorder(BorderFactory.createEtchedBorder());
    headerColumn.setBackground(Color.lightGray);
    headerColumn.setColumnSelectionAllowed(false);
    headerColumn.setCellSelectionEnabled(false);

    // Put it in a viewport that we can control a bit
    JViewport jv = new JViewport();
    jv.setView(headerColumn);
    jv.setPreferredSize(headerColumn.getMaximumSize());

    // With out shutting off autoResizeMode, our tables won't scroll
    // correctly (horizontally, anyway)
    jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    // We have to manually attach the row headers, but after that, the
    // scroll
    // pane keeps them in sync
    JScrollPane jsp = new JScrollPane(jt);
    jsp.setRowHeader(jv);
    jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader());
    getContentPane().add(jsp, BorderLayout.CENTER);
}

From source file:SelectionExample.java

public SelectionExample() {
    super("Selection Model Test");
    setSize(450, 350);/*from w ww. j  a v  a  2 s.  c  o  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        // We'll create a simple multiplication table to serve as a
        // noneditable
        // table with several rows and columns
        public int getRowCount() {
            return 10;
        }

        public int getColumnCount() {
            return 10;
        }

        public Object getValueAt(int r, int c) {
            return "" + (r + 1) * (c + 1);
        }
    };

    final JTable jt = new JTable(tm);

    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);

    // Now set up our selection controls
    JPanel controlPanel, buttonPanel, columnPanel, rowPanel;

    buttonPanel = new JPanel();
    final JCheckBox cellBox, columnBox, rowBox;
    cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled());
    columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed());
    rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed());
    cellBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setCellSelectionEnabled(cellBox.isSelected());
            columnBox.setSelected(jt.getColumnSelectionAllowed());
            rowBox.setSelected(jt.getRowSelectionAllowed());
        }
    });

    columnBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setColumnSelectionAllowed(columnBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    rowBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setRowSelectionAllowed(rowBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    buttonPanel.add(new JLabel("Selections allowed:"));
    buttonPanel.add(cellBox);
    buttonPanel.add(columnBox);
    buttonPanel.add(rowBox);

    columnPanel = new JPanel();
    ListSelectionModel csm = jt.getColumnModel().getSelectionModel();
    JLabel columnCounter = new JLabel("(Selected Column Indices Go Here)");
    csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm));
    columnPanel.add(new JLabel("Selected columns:"));
    columnPanel.add(columnCounter);

    rowPanel = new JPanel();
    ListSelectionModel rsm = jt.getSelectionModel();
    JLabel rowCounter = new JLabel("(Selected Row Indices Go Here)");
    rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm));
    rowPanel.add(new JLabel("Selected rows:"));
    rowPanel.add(rowCounter);

    controlPanel = new JPanel(new GridLayout(0, 1));
    controlPanel.add(buttonPanel);
    controlPanel.add(columnPanel);
    controlPanel.add(rowPanel);

    getContentPane().add(controlPanel, BorderLayout.SOUTH);
}

From source file:org.wso2.greg.plugin.Utils.java

/**
 * This method is used to create the Resources List UI from the given list of Resources(s).
 *
 * @param resourceInfos The list of Resources that the table is constructed.
 * @return ResourceSelectionResult which contains all the selected APIs and whether test suites and load
 * are needed to be generated./* w  ww .  java 2  s.co  m*/
 */
public static ResourceSelectionResult showSelectAPIDefDialog(List<ResourceInfo> resourceInfos) {

    final XFormDialog dialog = ADialogBuilder.buildDialog(ResourceModel.class);
    final Object[][] tableData = convertToTableData(resourceInfos);

    // --------------- start of API List table population section ------------------
    // We create a table model here with the converted data.
    TableModel tableModel = new AbstractTableModel() {
        Object[][] data = tableData;
        String[] columnNames = { "Name", "Version", "Provider", "Description" };

        @Override
        public int getRowCount() {
            return data.length;
        }

        @Override
        public int getColumnCount() {
            // We have a hardcoded set of columns
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            return data[rowIndex][columnIndex];
        }

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

    // We get the table that was ghttps://youtu.be/Vycy3GxbxUYenerated in the form and we set
    // some properties there.
    XFormField resourcesListFormField = dialog.getFormField(ResourceModel.RESOURCE_LIST);
    final JXTable table = ((JTableFormField) resourcesListFormField).getTable();
    table.setCellSelectionEnabled(false);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);
    table.setFillsViewportHeight(true);

    // We set the preferred size of all the parent forms until we get to the JScrollPane
    table.setPreferredScrollableViewportSize(new Dimension(600, 200));
    table.getParent().setPreferredSize(new Dimension(600, 200));
    table.getParent().getParent().setPreferredSize(new Dimension(600, 200));

    // Setting the table model
    table.setModel(tableModel);

    // This is to show a toolTip when hovering over the table cells. We need this because there could be long
    // descriptions and api names.
    table.addMouseMotionListener(new MouseMotionAdapter() {
        @Override
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            int row = table.rowAtPoint(p);
            int col = table.columnAtPoint(p);

            if (row == -1 || col == -1) {
                return;
            }
            table.setToolTipText(tableData[row][col].toString());
        }
    });

    // The purpose of this validator is the check whether there are at least one API selected from the table.
    resourcesListFormField.addFormFieldValidator(new XFormFieldValidator() {
        @Override
        public ValidationMessage[] validateField(XFormField xFormField) {
            if (table.getSelectedRowCount() <= 0) {
                return new ValidationMessage[] {
                        new ValidationMessage(HelpMessageConstants.API_SELECTION_VALIDATION_MSG,
                                dialog.getFormField(ResourceModel.RESOURCE_LIST)) };
            }
            return new ValidationMessage[0];
        }
    });
    // --
    // ----------------- End of Resource(s) List Table population section ----------------------

    // We get the radio button group and add a listener there. The purpose of the listener is to 'enable',
    // 'disable' the Load test radio button group based on the selected value of this group.
    // The reason is that, there is no meaning to create a Load test without a test suite.
    XFormRadioGroup testSuiteSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.TEST_SUITE);
    testSuiteSelection.setValue(ResourceConstants.RADIO_BUTTON_OPTIONS_NO);
    testSuiteSelection.setToolTip(HelpMessageConstants.TEST_SUITE_TOOLTIP_TEXT);

    testSuiteSelection.addFormFieldListener(new XFormFieldListener() {
        @Override
        public void valueChanged(XFormField xFormField, String newValue, String oldValue) {
            XFormRadioGroup loadTestSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.LOAD_TEST);
            if (ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(newValue)) {
                loadTestSelection.setEnabled(true);
            } else if (ResourceConstants.RADIO_BUTTON_OPTIONS_NO.equals(newValue)) {
                loadTestSelection.setEnabled(false);
            }
        }
    });

    XFormRadioGroup loadTestSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.LOAD_TEST);
    loadTestSelection.setToolTip(HelpMessageConstants.LOAD_TEST_TOOLTIP_TEXT);
    loadTestSelection.setValue(ResourceConstants.RADIO_BUTTON_OPTIONS_NO);

    if (dialog.show()) {
        int[] selected = table.getSelectedRows();
        ArrayList<ResourceInfo> selectedAPIs = new ArrayList<ResourceInfo>();
        for (int no : selected) {
            selectedAPIs.add(resourceInfos.get(no));
        }
        ResourceSelectionResult selectionResult = new ResourceSelectionResult();
        selectionResult.setResourceInfoList(selectedAPIs);
        selectionResult.setTestSuiteSelected(
                ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(testSuiteSelection.getValue()));
        selectionResult.setLoadTestSelected(
                ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(loadTestSelection.getValue()));

        return selectionResult;
    } else {
        return null;
    }

}

From source file:joinery.impl.Display.java

public static <V> void show(final DataFrame<V> df) {
    final List<Object> columns = new ArrayList<>(df.columns());
    final List<Class<?>> types = df.types();
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*  w  ww  . jav  a  2 s  .  c  om*/
        public void run() {
            final JFrame frame = new JFrame(title(df));
            final JTable table = new JTable(new AbstractTableModel() {
                private static final long serialVersionUID = 1L;

                @Override
                public int getRowCount() {
                    return df.length();
                }

                @Override
                public int getColumnCount() {
                    return df.size();
                }

                @Override
                public Object getValueAt(final int row, final int col) {
                    return df.get(row, col);
                }

                @Override
                public String getColumnName(final int col) {
                    return String.valueOf(columns.get(col));
                }

                @Override
                public Class<?> getColumnClass(final int col) {
                    return types.get(col);
                }
            });
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.add(new JScrollPane(table));
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:net.sf.jabref.gui.preftabs.TableColumnsTab.java

/**
 * Customization of external program paths.
 *
 * @param prefs a <code>JabRefPreferences</code> value
 *///from ww w . j  av a 2  s .  co m
public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) {
    this.prefs = prefs;
    this.frame = frame;
    setLayout(new BorderLayout());

    TableModel tm = new AbstractTableModel() {

        @Override
        public int getRowCount() {
            return rowCount;
        }

        @Override
        public int getColumnCount() {
            return 2;
        }

        @Override
        public Object getValueAt(int row, int column) {
            int internalRow = row;
            if (internalRow == 0) {
                return column == 0 ? InternalBibtexFields.NUMBER_COL : String.valueOf(ncWidth);
            }
            internalRow--;
            if (internalRow >= tableRows.size()) {
                return "";
            }
            Object rowContent = tableRows.get(internalRow);
            if (rowContent == null) {
                return "";
            }
            TableRow tr = (TableRow) rowContent;
            // Only two columns
            if (column == 0) {
                return tr.getName();
            } else {
                return tr.getLength() > 0 ? Integer.toString(tr.getLength()) : "";
            }
        }

        @Override
        public String getColumnName(int col) {
            return col == 0 ? Localization.lang("Field name") : Localization.lang("Column width");
        }

        @Override
        public Class<?> getColumnClass(int column) {
            if (column == 0) {
                return String.class;
            }
            return Integer.class;
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            return !((row == 0) && (col == 0));
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            tableChanged = true;
            // Make sure the vector is long enough.
            while (row >= tableRows.size()) {
                tableRows.add(new TableRow("", -1));
            }

            if ((row == 0) && (col == 1)) {
                ncWidth = Integer.parseInt(value.toString());
                return;
            }

            TableRow rowContent = tableRows.get(row - 1);

            if (col == 0) {
                rowContent.setName(value.toString());
                if ("".equals(getValueAt(row, 1))) {
                    setValueAt(String.valueOf(BibtexSingleField.DEFAULT_FIELD_LENGTH), row, 1);
                }
            } else {
                if (value == null) {
                    rowContent.setLength(-1);
                } else {
                    rowContent.setLength(Integer.parseInt(value.toString()));
                }
            }
        }

    };

    colSetup = new JTable(tm);
    TableColumnModel cm = colSetup.getColumnModel();
    cm.getColumn(0).setPreferredWidth(140);
    cm.getColumn(1).setPreferredWidth(80);

    FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:pref", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    JPanel pan = new JPanel();
    JPanel tabPanel = new JPanel();
    tabPanel.setLayout(new BorderLayout());
    JScrollPane sp = new JScrollPane(colSetup, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    colSetup.setPreferredScrollableViewportSize(new Dimension(250, 200));
    sp.setMinimumSize(new Dimension(250, 300));
    tabPanel.add(sp, BorderLayout.CENTER);
    JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL);
    toolBar.setFloatable(false);
    AddRowAction addRow = new AddRowAction();
    DeleteRowAction deleteRow = new DeleteRowAction();
    MoveRowUpAction moveUp = new MoveRowUpAction();
    MoveRowDownAction moveDown = new MoveRowDownAction();
    toolBar.setBorder(null);
    toolBar.add(addRow);
    toolBar.add(deleteRow);
    toolBar.addSeparator();
    toolBar.add(moveUp);
    toolBar.add(moveDown);
    tabPanel.add(toolBar, BorderLayout.EAST);

    fileColumn = new JCheckBox(Localization.lang("Show file column"));
    urlColumn = new JCheckBox(Localization.lang("Show URL/DOI column"));
    preferUrl = new JRadioButton(Localization.lang("Show URL first"));
    preferDoi = new JRadioButton(Localization.lang("Show DOI first"));
    ButtonGroup preferUrlDoiGroup = new ButtonGroup();
    preferUrlDoiGroup.add(preferUrl);
    preferUrlDoiGroup.add(preferDoi);

    urlColumn.addChangeListener(arg0 -> {
        preferUrl.setEnabled(urlColumn.isSelected());
        preferDoi.setEnabled(urlColumn.isSelected());
    });
    arxivColumn = new JCheckBox(Localization.lang("Show ArXiv column"));

    Collection<ExternalFileType> fileTypes = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
    String[] fileTypeNames = new String[fileTypes.size()];
    int i = 0;
    for (ExternalFileType fileType : fileTypes) {
        fileTypeNames[i++] = fileType.getName();
    }
    listOfFileColumns = new JList<>(fileTypeNames);
    JScrollPane listOfFileColumnsScrollPane = new JScrollPane(listOfFileColumns);
    listOfFileColumns.setVisibleRowCount(3);
    extraFileColumns = new JCheckBox(Localization.lang("Show extra columns"));
    extraFileColumns.addChangeListener(arg0 -> listOfFileColumns.setEnabled(extraFileColumns.isSelected()));

    /*** begin: special table columns and special fields ***/

    JButton helpButton = new HelpAction(Localization.lang("Help on special fields"), HelpFile.SPECIAL_FIELDS)
            .getHelpButton();

    rankingColumn = new JCheckBox(Localization.lang("Show rank"));
    qualityColumn = new JCheckBox(Localization.lang("Show quality"));
    priorityColumn = new JCheckBox(Localization.lang("Show priority"));
    relevanceColumn = new JCheckBox(Localization.lang("Show relevance"));
    printedColumn = new JCheckBox(Localization.lang("Show printed status"));
    readStatusColumn = new JCheckBox(Localization.lang("Show read status"));

    // "sync keywords" and "write special" fields may be configured mutually exclusive only
    // The implementation supports all combinations (TRUE+TRUE and FALSE+FALSE, even if the latter does not make sense)
    // To avoid confusion, we opted to make the setting mutually exclusive
    syncKeywords = new JRadioButton(Localization.lang("Synchronize with keywords"));
    writeSpecialFields = new JRadioButton(
            Localization.lang("Write values of special fields as separate fields to BibTeX"));
    ButtonGroup group = new ButtonGroup();
    group.add(syncKeywords);
    group.add(writeSpecialFields);

    specialFieldsEnabled = new JCheckBox(Localization.lang("Enable special fields"));
    specialFieldsEnabled.addChangeListener(event -> {
        boolean isEnabled = specialFieldsEnabled.isSelected();
        rankingColumn.setEnabled(isEnabled);
        qualityColumn.setEnabled(isEnabled);
        priorityColumn.setEnabled(isEnabled);
        relevanceColumn.setEnabled(isEnabled);
        printedColumn.setEnabled(isEnabled);
        readStatusColumn.setEnabled(isEnabled);
        syncKeywords.setEnabled(isEnabled);
        writeSpecialFields.setEnabled(isEnabled);
    });

    builder.appendSeparator(Localization.lang("Special table columns"));
    builder.nextLine();
    builder.append(pan);

    DefaultFormBuilder specialTableColumnsBuilder = new DefaultFormBuilder(
            new FormLayout("8dlu, 8dlu, 8cm, 8dlu, 8dlu, left:pref:grow",
                    "pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref"));
    CellConstraints cc = new CellConstraints();

    specialTableColumnsBuilder.add(specialFieldsEnabled, cc.xyw(1, 1, 3));
    specialTableColumnsBuilder.add(rankingColumn, cc.xyw(2, 2, 2));
    specialTableColumnsBuilder.add(relevanceColumn, cc.xyw(2, 3, 2));
    specialTableColumnsBuilder.add(qualityColumn, cc.xyw(2, 4, 2));
    specialTableColumnsBuilder.add(priorityColumn, cc.xyw(2, 5, 2));
    specialTableColumnsBuilder.add(printedColumn, cc.xyw(2, 6, 2));
    specialTableColumnsBuilder.add(readStatusColumn, cc.xyw(2, 7, 2));
    specialTableColumnsBuilder.add(syncKeywords, cc.xyw(2, 10, 2));
    specialTableColumnsBuilder.add(writeSpecialFields, cc.xyw(2, 11, 2));
    specialTableColumnsBuilder.add(helpButton, cc.xyw(1, 12, 2));

    specialTableColumnsBuilder.add(fileColumn, cc.xyw(5, 1, 2));
    specialTableColumnsBuilder.add(urlColumn, cc.xyw(5, 2, 2));
    specialTableColumnsBuilder.add(preferUrl, cc.xy(6, 3));
    specialTableColumnsBuilder.add(preferDoi, cc.xy(6, 4));
    specialTableColumnsBuilder.add(arxivColumn, cc.xyw(5, 5, 2));

    specialTableColumnsBuilder.add(extraFileColumns, cc.xyw(5, 6, 2));
    specialTableColumnsBuilder.add(listOfFileColumnsScrollPane, cc.xywh(5, 7, 2, 6));

    builder.append(specialTableColumnsBuilder.getPanel());
    builder.nextLine();

    /*** end: special table columns and special fields ***/

    builder.appendSeparator(Localization.lang("Entry table columns"));
    builder.nextLine();
    builder.append(pan);
    builder.append(tabPanel);
    builder.nextLine();
    builder.append(pan);
    JButton buttonWidth = new JButton(new UpdateWidthsAction());
    JButton buttonOrder = new JButton(new UpdateOrderAction());
    builder.append(buttonWidth);
    builder.nextLine();
    builder.append(pan);
    builder.append(buttonOrder);
    builder.nextLine();
    builder.append(pan);
    builder.nextLine();
    pan = builder.getPanel();
    pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(pan, BorderLayout.CENTER);
}

From source file:DOMTreeTest.java

public static JPanel elementPanel(Element e) {
        JPanel panel = new JPanel();
        panel.add(new JLabel("Element: " + e.getTagName()));
        final NamedNodeMap map = e.getAttributes();
        panel.add(new JTable(new AbstractTableModel() {
            public int getRowCount() {
                return map.getLength();
            }/*from w w  w  . j av a  2  s  .co  m*/

            public int getColumnCount() {
                return 2;
            }

            public Object getValueAt(int r, int c) {
                return c == 0 ? map.item(r).getNodeName() : map.item(r).getNodeValue();
            }
        }));
        return panel;
    }

From source file:com.opendoorlogistics.studio.components.geocoder.SearchResultsPanel.java

private void setTableModel() {
    final NumberFormat formatter = DecimalFormat.getInstance();
    formatter.setMaximumFractionDigits(4);

    // update table
    table.setModel(new AbstractTableModel() {

        @Override//  www  .j  a v a2  s. c  om
        public String getColumnName(int column) {
            switch (column) {
            case 0:
                return "Rank";

            case 1:
                return "Address";

            case 2:
                return "Latitude";

            case 3:
                return "Longitude";

            case 4:
                return "Class";

            case 5:
                return "Type";
            }
            throw new IndexOutOfBoundsException();
        }

        public Class<?> getColumnClass(int columnIndex) {
            return String.class;
        }

        @Override
        public Object getValueAt(int rowIndex, int column) {
            SearchResultPoint pnt = model.getSearchResults().get(rowIndex);
            switch (column) {
            case 0:
                return Integer.toString(rowIndex + 1);

            case 1:
                return pnt.getAddress();

            case 2:
                return formatter.format(pnt.getLatitude());

            case 3:
                return formatter.format(pnt.getLongitude());

            case 4:
                return pnt.getCls();

            case 5:
                return pnt.getType();
            }
            throw new IndexOutOfBoundsException();

        }

        @Override
        public int getRowCount() {
            return model.getSearchResults() != null ? model.getSearchResults().size() : 0;
        }

        @Override
        public int getColumnCount() {
            return 6;
        }
    });

    PackTableColumn.packAll(table, 6);

    if (table.getModel().getRowCount() > 0) {
        table.getSelectionModel().setSelectionInterval(0, 0);
    }

    readSelectedIntoModel();
}

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   w w  w .  j a va2 s .  c o 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:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java

private void displayTable(final MotifInstance instance) {
    final List<String> roles = (instance == null) ? new ArrayList<String>() : instance.getMotif().getRoles();
    TableModel model = new AbstractTableModel() {
        public String getColumnName(int col) {
            switch (col) {
            case 0:
                return "role";
            case 1:
                return "name";
            case 2:
                return "namespace";
            case 3:
                return "container";
            case 4:
                return "is abstract";
            case 5:
                return "type";
            case 6:
                return "cluster";
            default:
                return null;
            }/*from   w  w  w. ja  va 2s .co  m*/
        }

        public int getRowCount() {
            return roles.size();
        }

        public int getColumnCount() {
            return 7;
        }

        public Object getValueAt(int row, int col) {
            String role = roles.get(row);
            if (instance == null)
                return "";
            Vertex v = instance.getVertex(role);
            Object cluster = "TODO";
            if (cluster == null)
                cluster = "n/a";
            switch (col) {
            case 0:
                return role;
            case 1:
                return v.getName();
            case 2:
                return v.getNamespace();
            case 3:
                return v.getContainer();
            case 4:
                return v.isAbstract();
            case 5:
                return v.getType();
            case 6:
                return v.getCluster();
            default:
                return null;
            }
        }

        public boolean isCellEditable(int row, int col) {
            return false;
        }

        public void setValueAt(Object value, int row, int col) {
            // nothing to do - table is read only
        }
    };
    this.table.setModel(model);

}