Java Code Examples for javax.swing.table.DefaultTableModel#getColumnCount()
The following examples show how to use
javax.swing.table.DefaultTableModel#getColumnCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OldJTable.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 2
Source File: OldJTable.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 3
Source File: OldJTable.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 4
Source File: OldJTable.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 5
Source File: OldJTable.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 6
Source File: OldJTable.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 7
Source File: OldJTable.java From hottub with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 8
Source File: OldJTable.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 9
Source File: OldJTable.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 10
Source File: OldJTable.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 11
Source File: OldJTable.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 12
Source File: OldJTable.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 13
Source File: OldJTable.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
Example 14
Source File: SwingExtensions.java From groovy with Apache License 2.0 | 5 votes |
private static Object[] buildRowData(DefaultTableModel delegate, Object row) { int cols = delegate.getColumnCount(); Object[] rowData = new Object[cols]; int i = 0; for (Iterator<?> it = DefaultGroovyMethods.iterator(row); it.hasNext() && i < cols;) { rowData[i++] = it.next(); } return rowData; }
Example 15
Source File: Csv2TableModel.java From aurous-app with GNU General Public License v2.0 | 5 votes |
/** * * @param dtm * The DefaultTableModel to save to stream * @param out * The stream to which to save * */ public static void defaultTableModelToStream(final DefaultTableModel dtm, final Writer out) throws IOException { final String LINE_SEP = System.getProperty("line.separator"); final int numCols = dtm.getColumnCount(); final int numRows = dtm.getRowCount(); // Write headers String sep = ""; for (int i = 0; i < numCols; i++) { out.write(sep); out.write(dtm.getColumnName(i)); sep = ","; } out.write(LINE_SEP); for (int r = 0; r < numRows; r++) { sep = ""; for (int c = 0; c < numCols; c++) { out.write(sep); out.write(dtm.getValueAt(r, c).toString()); sep = ","; } out.write(LINE_SEP); } }
Example 16
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder encoder) { super.initialize(type, oldInstance, newInstance, encoder); DefaultTableModel m = (DefaultTableModel) oldInstance; for (int row = 0; row < m.getRowCount(); row++) { for (int col = 0; col < m.getColumnCount(); col++) { Object[] o = {m.getValueAt(row, col), row, col}; encoder.writeStatement(new Statement(oldInstance, "setValueAt", o)); } } }
Example 17
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder encoder) { super.initialize(type, oldInstance, newInstance, encoder); DefaultTableModel m = (DefaultTableModel) oldInstance; // Vector v = m.getDataVector(); // for (int i = 0; i < m.getRowCount(); i++) { // encoder.writeStatement(new Statement(oldInstance, "addRow", new Object[] { (Vector) v.get(i) })); // } for (int row = 0; row < m.getRowCount(); row++) { for (int col = 0; col < m.getColumnCount(); col++) { Object[] o = {m.getValueAt(row, col), row, col}; encoder.writeStatement(new Statement(oldInstance, "setValueAt", o)); } } }
Example 18
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder encoder) { super.initialize(type, oldInstance, newInstance, encoder); DefaultTableModel m = (DefaultTableModel) oldInstance; for (int row = 0; row < m.getRowCount(); row++) { for (int col = 0; col < m.getColumnCount(); col++) { Object[] o = {m.getValueAt(row, col), row, col}; encoder.writeStatement(new Statement(oldInstance, "setValueAt", o)); } } }
Example 19
Source File: FindDoubleEntriesTask.java From Zettelkasten with GNU General Public License v3.0 | 4 votes |
@Override protected void finished() { super.finished(); // when the task is finished, clear it doubleEntryTask = null; // hide task-progress bar jPanel1.setVisible(false); // create tablemodel for the table data, which is not editable DefaultTableModel tm = new DefaultTableModel(new Object[] {}, 0) { @Override public boolean isCellEditable(int row, int column) { return false; } }; // apply model to table jTable1.setModel(tm); // and delete all rows and columns tm.setRowCount(0); tm.setColumnCount(0); // now fill the table // check whether we have any multiple entries at all. if (!doubleentries.isEmpty()) { // create iterator for the list Iterator<Integer[]> it = doubleentries.iterator(); // iterate all multiple entries while (it.hasNext()) { // retrieve the row data Integer[] rowdata = it.next(); // if the rowdate has more columns than the table model, adjust // column count while (tm.getColumnCount()<rowdata.length) { tm.addColumn(String.valueOf(tm.getColumnCount()+1)); } // add it to the table model tm.addRow((Object[])rowdata); } // finally, enable table jTable1.setEnabled(true); } else { JOptionPane.showMessageDialog(null,resourceMap.getString("noMultipleEntriesFoundMsg"),resourceMap.getString("noMultipleEntriesFoundTitle"),JOptionPane.PLAIN_MESSAGE); setVisible(false); dispose(); } }
Example 20
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
private MainPanel() { super(new BorderLayout()); // <blockquote cite="FixedColumnExample.java"> // @author Nobuo Tamemasa Object[][] data = { {1, 11, "A", ES, ES, ES, ES, ES}, {2, 22, ES, "B", ES, ES, ES, ES}, {3, 33, ES, ES, "C", ES, ES, ES}, {4, 1, ES, ES, ES, "D", ES, ES}, {5, 55, ES, ES, ES, ES, "E", ES}, {6, 66, ES, ES, ES, ES, ES, "F"} }; String[] columnNames = {"fixed 1", "fixed 2", "A", "B", "C", "D", "E", "F"}; // </blockquote> DefaultTableModel model = new DefaultTableModel(data, columnNames) { @Override public Class<?> getColumnClass(int column) { return column < FIXED_COLUMN_RANGE ? Integer.class : Object.class; } }; RowSorter<? extends TableModel> sorter = new TableRowSorter<>(model); JTable fixedTable = new JTable(model); JTable table = new JTable(model); fixedTable.setSelectionModel(table.getSelectionModel()); for (int i = model.getColumnCount() - 1; i >= 0; i--) { if (i < FIXED_COLUMN_RANGE) { table.removeColumn(table.getColumnModel().getColumn(i)); fixedTable.getColumnModel().getColumn(i).setResizable(false); } else { fixedTable.removeColumn(fixedTable.getColumnModel().getColumn(i)); } } fixedTable.setRowSorter(sorter); fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fixedTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); table.setRowSorter(sorter); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); JScrollPane scroll = new JScrollPane(table); // JViewport viewport = new JViewport(); // viewport.setView(fixedTable); // viewport.setPreferredSize(fixedTable.getPreferredSize()); // scroll.setRowHeader(viewport); fixedTable.setPreferredScrollableViewportSize(fixedTable.getPreferredSize()); scroll.setRowHeaderView(fixedTable); scroll.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, fixedTable.getTableHeader()); scroll.getViewport().setBackground(Color.WHITE); scroll.getRowHeader().setBackground(Color.WHITE); // <blockquote cite="https://tips4java.wordpress.com/2008/11/05/fixed-column-table/"> // @author Rob Camick scroll.getRowHeader().addChangeListener(e -> { JViewport viewport = (JViewport) e.getSource(); scroll.getVerticalScrollBar().setValue(viewport.getViewPosition().y); }); // </blockquote> JButton addButton = new JButton("add"); addButton.addActionListener(e -> { sorter.setSortKeys(null); IntStream.range(0, 100).mapToObj(i -> new Object[] {i, i + 1, "A" + i, "B" + i}).forEach(model::addRow); }); add(scroll); add(addButton, BorderLayout.SOUTH); setPreferredSize(new Dimension(320, 240)); }