Java Code Examples for javax.swing.table.DefaultTableModel#setDataVector()
The following examples show how to use
javax.swing.table.DefaultTableModel#setDataVector() .
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: PropertyEditorPanel.java From netbeans with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void updateTableFromEditor() { synchronized (this) { if (updateing) { return; } updateing = true; DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel(); Vector columns = new Vector(2); Vector values = new Vector(); columns.add(dtm.getColumnName(0)); columns.add(dtm.getColumnName(1)); if (value != null) { for (String key : value.stringPropertyNames()) { Vector row = new Vector(2); row.add(key); row.add(value.getProperty(key, "")); values.add(row); } } dtm.setDataVector(values, columns); updateing = false; } }
Example 2
Source File: JtableUtils.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
/** * Adding column is done by creating new model by modifying older one.<p> * * Insert new column if column is outside the <code>limit</code> Adds new * column if selected column inside the <code>limit</code>table@param _table * target table * * @param limit the range to avoid inserting */ static void addcol(JTable table, int limit) { try { int sc = table.getSelectedColumn(); if (sc < limit - 1) { sc = table.getColumnCount() - 1; } DefaultTableModel tableM = (DefaultTableModel) table.getModel(); DefaultTableModel tableM1 = new DefaultTableModel(); TableModelListener[] listeners = tableM.getTableModelListeners(); tableM1.setDataVector(newvectoraddcol(tableM.getDataVector(), sc), getColumnIdentifiersaddcol(sc + 1, table)); table.setModel(tableM1); for (TableModelListener l : listeners) { tableM1.addTableModelListener(l); } } catch (Exception ex) { Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex); } }
Example 3
Source File: ChangeMVPDialog.java From MVPManager with MIT License | 6 votes |
/** * create a JTable instance * * @return */ private JTable newTableInstance(Object[][] objs) { DefaultTableModel mDefaultTableMoadel = new DefaultTableModel(); if (objs == null) { objs = new Object[1][2]; objs[0][0] = "void"; objs[0][1] = "method()"; } mDefaultTableMoadel.setDataVector(objs, new Object[]{"return", "method"}); JTable mJtable = new JTable(mDefaultTableMoadel) { @Override public void tableChanged(TableModelEvent e) { super.tableChanged(e); repaint(); } @Override public boolean isCellEditable(int row, int column) { return true; } }; return mJtable; }
Example 4
Source File: EditorMVPDialog.java From MVPManager with MIT License | 6 votes |
/** * create a JTable instance * * @return */ private JTable newTableInstance() { String[] defaultValue = {"void", "method()"}; DefaultTableModel mDefaultTableMoadel = new DefaultTableModel(); Object[][] object = new Object[1][2]; object[0][0] = "void"; object[0][1] = "method()"; mDefaultTableMoadel.setDataVector(object, new Object[]{"return", "method"}); JTable mJtable = new JTable(mDefaultTableMoadel) { @Override public void tableChanged(TableModelEvent e) { super.tableChanged(e); repaint(); } @Override public boolean isCellEditable(int row, int column) { return false; } }; return mJtable; }
Example 5
Source File: LayerControlList.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public LayerControlList() { table = new JTable() { public void tableChanged(TableModelEvent e) { super.tableChanged(e); repaint(); } }; Object[][] items = new Object[][] { { new JRadioButton(), new JCheckBox(), "A" }, { new JRadioButton(), new JCheckBox(), "B" }, { new JRadioButton(), new JCheckBox(), "Result" } }; DefaultTableModel dm = new DefaultTableModel(); dm.setDataVector(items, new Object[] { "", "", "Layer" }); ButtonGroup group1 = new ButtonGroup(); group1.add((JRadioButton) dm.getValueAt(0, 0)); group1.add((JRadioButton) dm.getValueAt(1, 0)); group1.add((JRadioButton) dm.getValueAt(2, 0)); addChangeListener((JToggleButton) dm.getValueAt(0, 1), 0); addChangeListener((JToggleButton) dm.getValueAt(1, 1), 1); addChangeListener((JToggleButton) dm.getValueAt(2, 1), 2); table.setModel(dm); // table.setShowHorizontalLines(false); // table.setShowVerticalLines(false); table.setGridColor(SystemColor.control); table.setBackground(SystemColor.control); table.getColumnModel().getColumn(0) .setCellRenderer(new RadioButtonRenderer()); table.getColumnModel().getColumn(0) .setCellEditor(new RadioButtonEditor(new JCheckBox())); table.getColumnModel().getColumn(1).setCellRenderer(new CheckBoxRenderer()); table.getColumnModel().getColumn(1) .setCellEditor(new CheckBoxEditor(new JCheckBox())); table.getColumnModel().getColumn(0).setMaxWidth(20); table.getColumnModel().getColumn(1).setMaxWidth(20); table.getColumnModel().getColumn(2).setMaxWidth(120); // table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); // JScrollPane scroll = new JScrollPane(table); setLayout(new BorderLayout()); add(table, BorderLayout.CENTER); }