Search in sources :

Example 6 with TableModel

use of javax.swing.table.TableModel in project jdk8u_jdk by JetBrains.

the class bug7055065 method createAndShowUI.

private static void createAndShowUI() {
    JFrame frame = new JFrame("SimpleTableDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel newContentPane = new JPanel();
    newContentPane.setOpaque(true);
    frame.setContentPane(newContentPane);
    final String[] columnNames = { "String", "Number" };
    final Object[][] data = { { "aaaa", new Integer(1) }, { "bbbb", new Integer(3) }, { "cccc", new Integer(2) }, { "dddd", new Integer(4) }, { "eeee", new Integer(5) } };
    table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 400));
    table.setFillsViewportHeight(true);
    TableModel dataModel = new AbstractTableModel() {

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

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

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

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

        public Class<?> getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }

        public boolean isCellEditable(int row, int col) {
            return col != 5;
        }

        public void setValueAt(Object aValue, int row, int column) {
            data[row][column] = aValue;
        }
    };
    table.setModel(dataModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(dataModel);
    table.setRowSorter(sorter);
    JScrollPane scrollPane = new JScrollPane(table);
    newContentPane.add(scrollPane);
    frame.pack();
    frame.setLocation(0, 0);
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Dimension(java.awt.Dimension) JFrame(javax.swing.JFrame) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter)

Example 7 with TableModel

use of javax.swing.table.TableModel in project azure-tools-for-java by Microsoft.

the class TableEntityForm method doOKAction.

@Override
protected void doOKAction() {
    final TableModel model = propertiesTable.getModel();
    final String partitionKey = model.getValueAt(0, 3).toString();
    final String rowKey = model.getValueAt(1, 3).toString();
    final Map<String, TableEntity.Property> properties = new LinkedHashMap<String, TableEntity.Property>();
    for (int row = 2; row != model.getRowCount(); row++) {
        TableEntity.PropertyType propertyType = (TableEntity.PropertyType) model.getValueAt(row, 2);
        String name = model.getValueAt(row, 1).toString();
        String value = model.getValueAt(row, 3).toString();
        TableEntity.Property property = getProperty(value, propertyType);
        properties.put(name, property);
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, tableEntity == null ? "Creating entity" : "Updating entity", false) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(true);
        /*try {
                    if (tableEntity == null) {
                        tableEntity = StorageClientSDKManager.getManager().createTableEntity(storageAccount,
                                tableName,
                                partitionKey,
                                rowKey,
                                properties);
                    } else {
                        tableEntity.getProperties().clear();
                        tableEntity.getProperties().putAll(properties);
                        tableEntity = StorageClientSDKManager.getManager().updateTableEntity(storageAccount, tableEntity);
                    }

                    onFinish.run();
                } catch (AzureCmdException e) {
                    String msg = "An error occurred while attempting to create entity." + "\n" + String.format(message("webappExpMsg"), e.getMessage());
                    PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, e);
                }*/
        }
    });
    dispose();
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 8 with TableModel

use of javax.swing.table.TableModel in project otapij by FellowTraveler.

the class MarketTradesTableModel method setValue.

public void setValue(Map values, JTable table) {
    clearValue();
    System.out.println("values.size():" + values.size());
    Set set = values.keySet();
    Iterator iterator = set.iterator();
    int i = 0;
    data = new Object[values.size()][];
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String[] row = (String[]) values.get(key);
        data[i] = row;
        i++;
    }
    if (values.size() > 0) {
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(this);
        table.setRowSorter(sorter);
    }
    fireTableDataChanged();
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) TableRowSorter(javax.swing.table.TableRowSorter) DefaultTableModel(javax.swing.table.DefaultTableModel) TableModel(javax.swing.table.TableModel)

Example 9 with TableModel

use of javax.swing.table.TableModel in project otapij by FellowTraveler.

the class BitcoinReceivingAddrTableModel method setValue.

public void setValue(Map values, JTable receiveAddrTable) {
    clearValue();
    System.out.println("values.size():" + values.size());
    Set set = values.keySet();
    Iterator iterator = set.iterator();
    int i = 0;
    data = new Object[values.size()][];
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String[] row = (String[]) values.get(key);
        data[i] = row;
        i++;
    }
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(this);
    receiveAddrTable.setRowSorter(sorter);
    /*TableColumnModel tcm = receiveAddrTable.getColumnModel();
      System.out.println("receivedTable.getColumn()"+tcm.getColumnCount());
      if(tcm.getColumnCount()==6){
        receiveAddrTable.removeColumn(tcm.getColumn(5));
      }*/
    fireTableDataChanged();
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) TableRowSorter(javax.swing.table.TableRowSorter) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 10 with TableModel

use of javax.swing.table.TableModel in project EnrichmentMapApp by BaderLab.

the class DataSetSelector method updateSelectionButtons.

private void updateSelectionButtons() {
    final int rowCount = getTable().getRowCount();
    TableModel model = getTable().getModel();
    boolean hasUnchecked = false;
    boolean hasChecked = false;
    for (int i = 0; i < rowCount; i++) {
        final boolean checked = (boolean) model.getValueAt(i, SELECTED_COL_IDX);
        if (!hasUnchecked)
            hasUnchecked = !checked;
        if (!hasChecked)
            hasChecked = checked;
        if (hasUnchecked && hasChecked)
            break;
    }
    getSelectAllButton().setEnabled(hasUnchecked);
    getSelectNoneButton().setEnabled(hasChecked);
}
Also used : TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel)

Aggregations

TableModel (javax.swing.table.TableModel)53 AbstractTableModel (javax.swing.table.AbstractTableModel)11 JTable (javax.swing.JTable)9 DefaultTableModel (javax.swing.table.DefaultTableModel)9 TableColumn (javax.swing.table.TableColumn)9 ArrayList (java.util.ArrayList)8 TableRowSorter (javax.swing.table.TableRowSorter)8 TableCellRenderer (javax.swing.table.TableCellRenderer)6 ActionEvent (java.awt.event.ActionEvent)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 TableCellEditor (javax.swing.table.TableCellEditor)5 Component (java.awt.Component)4 ActionListener (java.awt.event.ActionListener)4 List (java.util.List)4 Set (java.util.Set)4 TableColumnModel (javax.swing.table.TableColumnModel)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)2