Java Code Examples for javax.swing.table.DefaultTableModel#insertRow()
The following examples show how to use
javax.swing.table.DefaultTableModel#insertRow() .
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: MoveArrangementGroupingRuleDownAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { ArrangementGroupingRulesControl control = e.getData(ArrangementGroupingRulesControl.KEY); if (control == null) { return; } int[] rows = control.getSelectedRows(); int row = rows[0]; if (rows.length != 1 || rows[0] == control.getRowCount() - 1) { return; } if (control.isEditing()) { control.getCellEditor().stopCellEditing(); } DefaultTableModel model = control.getModel(); Object value = model.getValueAt(row, 0); model.removeRow(row); model.insertRow(row + 1, new Object[] { value }); control.getSelectionModel().setSelectionInterval(row + 1, row + 1); }
Example 2
Source File: MoveArrangementGroupingRuleUpAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { ArrangementGroupingRulesControl control = e.getData(ArrangementGroupingRulesControl.KEY); if (control == null) { return; } int[] rows = control.getSelectedRows(); int row = rows[0]; if (rows.length != 1 || row == 0) { return; } if (control.isEditing()) { control.getCellEditor().stopCellEditing(); } DefaultTableModel model = control.getModel(); Object value = model.getValueAt(row, 0); model.removeRow(row); model.insertRow(row - 1, new Object[] { value }); control.getSelectionModel().setSelectionInterval(row - 1, row - 1); }
Example 3
Source File: TimeComponentPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void changeRow(Object fo, String key) { Integer row = key2RowNumber.get(key); DefaultTableModel model = (DefaultTableModel) times.getModel(); if (row != null) { model.removeRow(row); } TimesCollectorPeer.Description desc = TimesCollectorPeer.getDefault().getDescription(fo, key); if (desc == null) { return ; } if (row == null) { key2RowNumber.put(key, row = model.getRowCount()); } model.insertRow(row, new Object[] {desc.getMessage(), desc.getTime()}); }
Example 4
Source File: EventViewer.java From jaamsim with Apache License 2.0 | 6 votes |
public void updateConditionals() { // Make a copy of the conditional data to avoid concurrent modification exceptions try { condEvents.clear(); evtMan.getConditionalDataList(condEvents); } catch (Exception e) { setDirty(true); return; } // Build the table entries DefaultTableModel tableModel = (DefaultTableModel) condList.getModel(); String[] condData = new String[1]; for (int i = 0; i < condEvents.size(); i++) { condData[0] = condEvents.get(i); tableModel.insertRow(i, condData); } tableModel.setRowCount(condEvents.size()); condEvents.clear(); }
Example 5
Source File: VariableFormatterEditPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void moveUpVarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpVarButtonActionPerformed int index = childrenVariablesTable.getSelectedRow(); if (index <= 0) return ; DefaultTableModel model = (DefaultTableModel) childrenVariablesTable.getModel(); Object[] row = new Object[] { model.getValueAt(index, 0), model.getValueAt(index, 1) }; model.removeRow(index); model.insertRow(index - 1, row); childrenVariablesTable.getSelectionModel().setSelectionInterval(index - 1, index - 1); }
Example 6
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { TransferHandler.DropLocation tdl = info.getDropLocation(); if (!(tdl instanceof JTable.DropLocation)) { return false; } JTable.DropLocation dl = (JTable.DropLocation) tdl; JTable target = (JTable) info.getComponent(); DefaultTableModel model = (DefaultTableModel) target.getModel(); // boolean insert = dl.isInsert(); int max = model.getRowCount(); int index = dl.getRow(); // index = index < 0 ? max : index; // If it is out of range, it is appended to the end // index = Math.min(index, max); index = index >= 0 && index < max ? index : max; addIndex = index; // target.setCursor(Cursor.getDefaultCursor()); try { List<?> values = (List<?>) info.getTransferable().getTransferData(FLAVOR); if (Objects.equals(source, target)) { addCount = values.size(); } Object[] type = new Object[0]; for (Object o: values) { int row = index++; // model.insertRow(row, (Vector<?>) o); model.insertRow(row, ((List<?>) o).toArray(type)); target.getSelectionModel().addSelectionInterval(row, row); } return true; } catch (UnsupportedFlavorException | IOException ex) { return false; } }
Example 7
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { TransferHandler.DropLocation tdl = info.getDropLocation(); if (!(tdl instanceof JTable.DropLocation)) { return false; } JTable.DropLocation dl = (JTable.DropLocation) tdl; JTable target = (JTable) info.getComponent(); DefaultTableModel model = (DefaultTableModel) target.getModel(); // boolean insert = dl.isInsert(); int max = model.getRowCount(); int index = dl.getRow(); // index = index < 0 ? max : index; // If it is out of range, it is appended to the end // index = Math.min(index, max); index = index >= 0 && index < max ? index : max; addIndex = index; // target.setCursor(Cursor.getDefaultCursor()); try { List<?> values = (List<?>) info.getTransferable().getTransferData(FLAVOR); addCount = values.size(); Object[] type = new Object[0]; for (Object o: values) { int row = index++; // model.insertRow(row, (Vector<?>) o); model.insertRow(row, ((List<?>) o).toArray(type)); target.getSelectionModel().addSelectionInterval(row, row); } return true; } catch (UnsupportedFlavorException | IOException ex) { return false; } }
Example 8
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { TransferHandler.DropLocation tdl = info.getDropLocation(); if (!(tdl instanceof JTable.DropLocation)) { return false; } JTable.DropLocation dl = (JTable.DropLocation) tdl; JTable target = (JTable) info.getComponent(); DefaultTableModel model = (DefaultTableModel) target.getModel(); // boolean insert = dl.isInsert(); int max = model.getRowCount(); int index = dl.getRow(); // index = index < 0 ? max : index; // If it is out of range, it is appended to the end // index = Math.min(index, max); index = index >= 0 && index < max ? index : max; addIndex = index; // target.setCursor(Cursor.getDefaultCursor()); try { List<?> values = (List<?>) info.getTransferable().getTransferData(FLAVOR); if (Objects.equals(source, target)) { addCount = values.size(); } Object[] type = new Object[0]; for (Object o: values) { int row = index++; // model.insertRow(row, (Vector<?>) o); model.insertRow(row, ((List<?>) o).toArray(type)); target.getSelectionModel().addSelectionInterval(row, row); } return true; } catch (UnsupportedFlavorException | IOException ex) { return false; } }
Example 9
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { TransferHandler.DropLocation tdl = info.getDropLocation(); if (!(tdl instanceof JTable.DropLocation)) { return false; } JTable.DropLocation dl = (JTable.DropLocation) tdl; JTable target = (JTable) info.getComponent(); DefaultTableModel model = (DefaultTableModel) target.getModel(); int max = model.getRowCount(); int index = dl.getRow(); index = index >= 0 && index < max ? index : max; addIndex = index; try { List<?> values = (List<?>) info.getTransferable().getTransferData(FLAVOR); addCount = values.size(); Object[] array = new Object[0]; for (Object o: values) { int row = index++; // model.insertRow(row, (Vector<?>) o); model.insertRow(row, ((List<?>) o).toArray(array)); target.getSelectionModel().addSelectionInterval(row, row); } return true; } catch (UnsupportedFlavorException | IOException ex) { return false; } }
Example 10
Source File: File.java From xunxian with Apache License 2.0 | 5 votes |
/** * 自动扫货八卦灵石类加载数据 * <li>加载stone.xnx3文件,若是加载中数据出错,则自动使用默认数据data.Stone.stoneBak */ public void saoHuoStoneLoad(){ Lang lang=new Func.Lang(); try { String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\stone.xnx3", "UTF-8"); xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content); JSONArray j=JSONArray.fromObject(xnx3_content); List l=j.toList(j); // List l=new Stone().stoneBak(); SaoHuoFunc saoHuoFunc=new SaoHuoFunc(); Command.JframeSaoHuo.stonejTable.removeAll(); //移除所有的重新添加 DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.stonejTable.getModel(); Command.saoHuoStone.clear(); //情空,重新放入 tableModel.getDataVector().clear(); //清空所有 new Func.File().log("八卦灵石载入:"+l.size()+"条数据"); for (int i = l.size()-1; i >-1; i--) { JSONArray jSub=JSONArray.fromObject(l.get(i)); List lSub=jSub.toList(jSub); // System.out.println(jSub.get(0)+"-->"+jSub.get(1)); String key=jSub.getString(0); int value=lang.Integer_(jSub.getString(1), 2); Command.saoHuoStone.put(key, value); Vector rowData = new Vector(); rowData.add(key); rowData.add(saoHuoFunc.moneyToString(value)); rowData.add(value); tableModel.insertRow(0, rowData); rowData=null; } saoHuoFunc=null; new Func.File().log("加载自动扫货八卦灵石类数据完毕"); } catch (Exception e) { e.printStackTrace(); new Func.Message().showMessageDialog("初始化失败!<br/>加载自动扫货八卦灵石类数据异常<br/>八卦灵石类数据已自动还原为初始数据"); // Command.saoHuoStone=new Stone().stoneBak(); new Func.File().log("加载自动扫货八卦灵石类数据异常!"); } lang=null; }
Example 11
Source File: Debugger.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void start() { Protocol prot; ProtocolStack stack; ProtocolView view=null; if(channel == null) return; stack=channel.getProtocolStack(); prots=stack.getProtocols(); setBounds(new Rectangle(30, 30, 300, 300)); table_model=new DefaultTableModel(); table=new JTable(table_model); table.setFont(helvetica_12); scroll_pane=new JScrollPane(table); table_model.setColumnIdentifiers(new String[]{"Index", "Name", "up", "down"}); getContentPane().add(scroll_pane); show(); for(int i=0; i < prots.size(); i++) { prot=(Protocol)prots.elementAt(i); view=new ProtocolView(prot, table_model, i, cummulative); prot.setObserver(view); table_model.insertRow(i, new Object[]{"" + (i + 1), prot.getName(), prot.getUpQueue().size() + "", prot.getDownQueue().size() + "", "0", "0"}); //prot_view=CreateProtocolView(prot.getName()); //if(prot_view != null) { //JFrame f=new JFrame("New View for " + prot.GetName()); //f.getContentPane().add(prot_view); //f.show(); //} } }
Example 12
Source File: MutableTable.java From typometer with Apache License 2.0 | 5 votes |
private void moveRows(Collection<Integer> indices, int delta, Consumer<Integer> listener) { DefaultTableModel model = getMutableModel(); for (int index : indices) { Vector row = (Vector) model.getDataVector().get(index); model.removeRow(index); model.insertRow(index + delta, row); listener.accept(index); } }
Example 13
Source File: Debugger.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void start() { Protocol prot; ProtocolStack stack; ProtocolView view=null; if(channel == null) return; stack=channel.getProtocolStack(); prots=stack.getProtocols(); setBounds(new Rectangle(30, 30, 300, 300)); table_model=new DefaultTableModel(); table=new JTable(table_model); table.setFont(helvetica_12); scroll_pane=new JScrollPane(table); table_model.setColumnIdentifiers(new String[]{"Index", "Name", "up", "down"}); getContentPane().add(scroll_pane); show(); for(int i=0; i < prots.size(); i++) { prot=(Protocol)prots.elementAt(i); view=new ProtocolView(prot, table_model, i, cummulative); prot.setObserver(view); table_model.insertRow(i, new Object[]{"" + (i + 1), prot.getName(), prot.getUpQueue().size() + "", prot.getDownQueue().size() + "", "0", "0"}); //prot_view=CreateProtocolView(prot.getName()); //if(prot_view != null) { //JFrame f=new JFrame("New View for " + prot.GetName()); //f.getContentPane().add(prot_view); //f.show(); //} } }
Example 14
Source File: VariableFormatterEditPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void moveDownVarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownVarButtonActionPerformed int index = childrenVariablesTable.getSelectedRow(); if (index < 0) return ; DefaultTableModel model = (DefaultTableModel) childrenVariablesTable.getModel(); if (index >= (model.getRowCount() - 1)) return ; Object[] row = new Object[] { model.getValueAt(index, 0), model.getValueAt(index, 1) }; model.removeRow(index); model.insertRow(index + 1, row); childrenVariablesTable.getSelectionModel().setSelectionInterval(index + 1, index + 1); }
Example 15
Source File: CustomizedTable.java From DeconvolutionLab2 with GNU General Public License v3.0 | 5 votes |
/** * Add a row at the top of the table. * * @param row */ public void insert(Object[] row) { DefaultTableModel model = (DefaultTableModel) getModel(); int i = 0; try { model.insertRow(0, row); getSelectionModel().setSelectionInterval(i, i); scrollRectToVisible(new Rectangle(getCellRect(i, 0, true))); } catch (Exception e) { } repaint(); }
Example 16
Source File: File.java From xunxian with Apache License 2.0 | 4 votes |
/** * 自动扫货宠物壳子类加载数据 * <li>加载pet.xnx3文件,若是加载中数据出错,则自动使用默认数据data.Pet.petBak */ public void saoHuoPetLoad(){ Lang lang=new Func.Lang(); Command.saoHuoPet.clear(); //清空Map Command.saoHuoPet=new data.Pet().petBak(); try { String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\pet.xnx3", "UTF-8"); xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content); JSONArray j=JSONArray.fromObject(xnx3_content); List l=j.toList(j); // List l=new Pet().petBak(); SaoHuoFunc saoHuoFunc=new SaoHuoFunc(); Command.JframeSaoHuo.petjTable.removeAll(); //移除所有的重新添加 DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.petjTable.getModel(); tableModel.getDataVector().clear(); //清空所有 new Func.File().log("宠物壳子载入:"+l.size()+"条数据"); for (int i = l.size()-1; i >-1; i--) { JSONArray jSub=JSONArray.fromObject(l.get(i)); List lSub=jSub.toList(jSub); String key=jSub.getString(0); int value=lang.Integer_(jSub.getString(1), 2); System.out.println("Key->"+key+"-->"+value); Command.saoHuoPet.put(key, value); } Set<Map.Entry<String, Integer>> set = Command.saoHuoPet.entrySet(); for (Iterator<Map.Entry<String, Integer>> it = set.iterator(); it.hasNext();) { Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next(); Vector rowData = new Vector(); rowData.add(entry.getKey()); rowData.add(saoHuoFunc.moneyToString(entry.getValue())); rowData.add(entry.getValue()); tableModel.insertRow(0, rowData); rowData=null; } saoHuoFunc=null; new Func.File().log("加载自动扫货宠物壳子类数据完毕"); } catch (Exception e) { e.printStackTrace(); new Func.Message().showMessageDialog("初始化失败!<br/>加载自动扫货宠物壳子类数据异常<br/>宠物壳子类数据已自动还原为初始数据"); // Command.saoHuoStone=new Stone().stoneBak(); new Func.File().log("加载自动扫货宠物壳子类数据异常!"); } lang=null; }
Example 17
Source File: File.java From xunxian with Apache License 2.0 | 4 votes |
/** * 自动扫货风物志类加载数据 * <li>加载fengWuZhi.xnx3文件,若是加载中数据出错,则自动使用默认数据data.FengWuZhi() */ public void saoHuoFengWuZhiLoad(){ Lang lang=new Func.Lang(); Command.saoHuoFengWuZhi.clear(); //清空Map Command.saoHuoFengWuZhi=new data.FengWuZhi().fengWuZhiBak(); try { String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\fengWuZhi.xnx3", "UTF-8"); xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content); JSONArray j=JSONArray.fromObject(xnx3_content); List l=j.toList(j); // List l=new Pet().petBak(); SaoHuoFunc saoHuoFunc=new SaoHuoFunc(); Command.JframeSaoHuo.fengWuZhijTable.removeAll(); //移除所有的重新添加 DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.fengWuZhijTable.getModel(); tableModel.getDataVector().clear(); //清空所有 new Func.File().log("风物志载入:"+l.size()+"条数据"); for (int i = l.size()-1; i >-1; i--) { JSONArray jSub=JSONArray.fromObject(l.get(i)); List lSub=jSub.toList(jSub); String key=jSub.getString(0); int value=lang.Integer_(jSub.getString(1), 2); Command.saoHuoFengWuZhi.put(key, value); } Set<Map.Entry<String, Integer>> set = Command.saoHuoFengWuZhi.entrySet(); for (Iterator<Map.Entry<String, Integer>> it = set.iterator(); it.hasNext();) { Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next(); Vector rowData = new Vector(); rowData.add(entry.getKey()); rowData.add(saoHuoFunc.moneyToString(entry.getValue())); rowData.add(entry.getValue()); tableModel.insertRow(0, rowData); rowData=null; } saoHuoFunc=null; new Func.File().log("加载自动扫货风物志类数据完毕"); } catch (Exception e) { e.printStackTrace(); } lang=null; }
Example 18
Source File: File.java From xunxian with Apache License 2.0 | 4 votes |
/** * 自动扫货传奇配方类加载数据 * <li>加载legend.xnx3文件,若是加载中数据出错,则自动使用默认数据data.Legend() */ public void saoHuoLegendLoad(){ Lang lang=new Func.Lang(); Command.saoHuoLegend.clear(); //清空Map Command.saoHuoLegend=new data.Legend().legendBak(); try { String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\legend.xnx3", "UTF-8"); xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content); JSONArray j=JSONArray.fromObject(xnx3_content); List l=j.toList(j); // List l=new Pet().petBak(); SaoHuoFunc saoHuoFunc=new SaoHuoFunc(); Command.JframeSaoHuo.legendjTable.removeAll(); //移除所有的重新添加 DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.legendjTable.getModel(); tableModel.getDataVector().clear(); //清空所有 new Func.File().log("传奇配方载入:"+l.size()+"条数据"); for (int i = l.size()-1; i >-1; i--) { JSONArray jSub=JSONArray.fromObject(l.get(i)); List lSub=jSub.toList(jSub); String key=jSub.getString(0); int value=lang.Integer_(jSub.getString(1), 2); Command.saoHuoLegend.put(key, value); } Set<Map.Entry<String, Integer>> set = Command.saoHuoLegend.entrySet(); for (Iterator<Map.Entry<String, Integer>> it = set.iterator(); it.hasNext();) { Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next(); Vector rowData = new Vector(); rowData.add(entry.getKey()); rowData.add(saoHuoFunc.moneyToString(entry.getValue())); rowData.add(entry.getValue()); tableModel.insertRow(0, rowData); rowData=null; } saoHuoFunc=null; new Func.File().log("加载自动扫货传奇配方类数据完毕"); } catch (Exception e) { e.printStackTrace(); } lang=null; }
Example 19
Source File: ClassDialogue.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
public Object extraEditWindow(Object o, int row, JTable jtable) { JPanel mainPanel = new JPanel(); JPanel leftText = new JPanel(); JPanel rightInput = new JPanel(); mainPanel.setLayout(new BorderLayout(15, 15)); leftText.setLayout(new GridLayout(1, 1)); rightInput.setLayout(new GridLayout(1, 1)); if (isModifiedSpecial(o.getClass().getName(), o.getClass())) { rightInput.add(wrap(o, getModifiedSpecial(o, o.getClass().getName(), o.getClass()))); } else if (hasNoChilds(o.getClass())) { try { rightInput.add(wrap(o, ClassDialogue.this.getComponent(o.getClass(), o))); } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } else { JButton edit = new JButton(JByteMod.res.getResource("edit")); edit.addActionListener(e -> { try { ClassDialogue dialogue = ClassDialogue.this.init(o); dialogue.open(); } catch (Exception ex) { ex.printStackTrace(); } }); rightInput.add(wrap(o, edit)); } mainPanel.add(leftText, BorderLayout.WEST); mainPanel.add(rightInput, BorderLayout.CENTER); leftText.add(new JLabel(formatText(o.getClass().getSimpleName() + ":"))); Object newObject = null; if (JOptionPane.showConfirmDialog(null, mainPanel, "Edit List Item", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { for (Component c : rightInput.getComponents()) { WrappedPanel wp = (WrappedPanel) c; if (o != null) { Component child = wp.getComponent(0); if (isModifiedSpecial(o.getClass().getName(), o.getClass())) { newObject = getSpecialValue(object, o.getClass().getName(), o.getClass(), o, wp); } else if (hasNoChilds(o.getClass())) { newObject = getValue(o.getClass(), child); } } } if (newObject == null) { newObject = o; } if (row != -1) { DefaultTableModel lm = (DefaultTableModel) jtable.getModel(); lm.insertRow(row, new Object[] { row, newObject.getClass().getSimpleName(), newObject }); lm.removeRow(row + 1); } return newObject; } return null; }
Example 20
Source File: SwingExtensions.java From groovy with Apache License 2.0 | 3 votes |
/** * Allow DefaultTableModel to work with subscript operators.<p> * <b>WARNING:</b> this operation does not replace the item at the * specified index, rather it inserts the item at that index, thus * increasing the size of the model by 1.<p> * <p> * if row.size < model.size -> row will be padded with nulls<br> * if row.size > model.size -> additional columns will be discarded * * @param self a DefaultTableModel * @param index an index * @param row the row to insert at the given index * @since 1.6.4 */ public static void putAt(DefaultTableModel self, int index, Object row) { if (row == null) { // adds an empty row self.insertRow(index, (Object[]) null); return; } self.insertRow(index, buildRowData(self, row)); }