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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations