Search in sources :

Example 1 with AbstractTableModel

use of javax.swing.table.AbstractTableModel 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 2 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class EditMigrationDialog method edit.

private void edit() {
    EditMigrationEntryDialog dialog = new EditMigrationEntryDialog(myProject);
    int selected = myTable.getSelectedRow();
    if (selected < 0)
        return;
    MigrationMapEntry entry = myMigrationMap.getEntryAt(selected);
    dialog.setEntry(entry);
    if (!dialog.showAndGet()) {
        return;
    }
    dialog.updateEntry(entry);
    AbstractTableModel model = (AbstractTableModel) myTable.getModel();
    model.fireTableRowsUpdated(selected, selected);
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 3 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class EditMigrationDialog method moveUp.

private void moveUp() {
    int selected = myTable.getSelectedRow();
    if (selected < 1)
        return;
    MigrationMapEntry entry = myMigrationMap.getEntryAt(selected);
    MigrationMapEntry previousEntry = myMigrationMap.getEntryAt(selected - 1);
    myMigrationMap.setEntryAt(previousEntry, selected);
    myMigrationMap.setEntryAt(entry, selected - 1);
    AbstractTableModel model = (AbstractTableModel) myTable.getModel();
    model.fireTableRowsUpdated(selected - 1, selected);
    myTable.setRowSelectionInterval(selected - 1, selected - 1);
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 4 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class EditMigrationDialog method createTable.

private JBTable createTable() {
    final String[] names = { RefactoringBundle.message("migration.type.column.header"), RefactoringBundle.message("migration.old.name.column.header"), RefactoringBundle.message("migration.new.name.column.header") };
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return 3;
        }

        public int getRowCount() {
            return myMigrationMap.getEntryCount();
        }

        public Object getValueAt(int row, int col) {
            MigrationMapEntry entry = myMigrationMap.getEntryAt(row);
            if (col == 0) {
                if (entry.getType() == MigrationMapEntry.PACKAGE && entry.isRecursive()) {
                    return RefactoringBundle.message("migration.package.with.subpackages");
                } else if (entry.getType() == MigrationMapEntry.PACKAGE && !entry.isRecursive()) {
                    return RefactoringBundle.message("migration.package");
                } else {
                    return RefactoringBundle.message("migration.class");
                }
            }
            String suffix = (entry.getType() == MigrationMapEntry.PACKAGE ? ".*" : "");
            if (col == 1) {
                return entry.getOldName() + suffix;
            } else {
                return entry.getNewName() + suffix;
            }
        }

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

        public Class getColumnClass(int c) {
            return String.class;
        }

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

        public void setValueAt(Object aValue, int row, int column) {
        }
    };
    // Create the table
    myTable = new JBTable(dataModel);
    myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.setPreferredScrollableViewportSize(new Dimension(300, myTable.getRowHeight() * 10));
    return myTable;
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel) JBTable(com.intellij.ui.table.JBTable) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 5 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.

the class ImportLayoutPanel method addBlankLine.

private void addBlankLine() {
    int selected = myImportLayoutTable.getSelectedRow() + 1;
    if (selected < 0) {
        selected = myImportLayoutList.getEntryCount();
    }
    myImportLayoutList.insertEntryAt(PackageEntry.BLANK_LINE_ENTRY, selected);
    AbstractTableModel model = (AbstractTableModel) myImportLayoutTable.getModel();
    model.fireTableRowsInserted(selected, selected);
    myImportLayoutTable.setRowSelectionInterval(selected, selected);
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Aggregations

AbstractTableModel (javax.swing.table.AbstractTableModel)45 TableModel (javax.swing.table.TableModel)8 JTable (javax.swing.JTable)7 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)4 JBTable (com.intellij.ui.table.JBTable)3 JFrame (javax.swing.JFrame)3 JPanel (javax.swing.JPanel)3 EmptyBorder (javax.swing.border.EmptyBorder)3 JTableHeader (javax.swing.table.JTableHeader)3 IndTestDSep (edu.cmu.tetrad.search.IndTestDSep)2 IntTextField (edu.cmu.tetradapp.util.IntTextField)2 Font (java.awt.Font)2 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2