public void actionPerformed(ActionEvent evt) { // 删除原来的JTable(JTable使用scrollPane来包装) if (scrollPane != null) { jf.remove(scrollPane); } try ( // 根据用户输入的SQL执行查询 ResultSet rs = stmt.executeQuery(sqlField.getText())) { // 取出ResultSet的MetaData ResultSetMetaData rsmd = rs.getMetaData(); Vector<String> columnNames = new Vector<>(); Vector<Vector<String>> data = new Vector<>(); // 把ResultSet的所有列名添加到Vector里 for (int i = 0; i < rsmd.getColumnCount(); i++) { columnNames.add(rsmd.getColumnName(i + 1)); } // 把ResultSet的所有记录添加到Vector里 while (rs.next()) { Vector<String> v = new Vector<>(); for (int i = 0; i < rsmd.getColumnCount(); i++) { v.add(rs.getString(i + 1)); } data.add(v); } // 创建新的JTable JTable table = new JTable(data, columnNames); scrollPane = new JScrollPane(table); // 添加新的Table jf.add(scrollPane); // 更新主窗口 jf.validate(); } catch (Exception e) { e.printStackTrace(); } }
public void updateTableData() { // we need to get the stored filters Object[] row_data; rowData.removeAllElements(); for (Iterator it = m_filters.keySet().iterator(); it.hasNext(); ) { row_data = new Object[2]; row_data[0] = it.next(); row_data[1] = m_filters.get(row_data[0]); rowData.add(row_data); } fireTableDataChanged(); }
private void addNewRow() { Object[] row_data = new Object[2]; if (rowData.size() < 1) { // add a new html filter row_data[0] = "text/html"; } else { row_data[0] = "Enter MIME type"; } row_data[1] = "Replace with " + mimeTypeEditorBuilder.getValueClassName() + " class name"; logger.debug3("Adding new row"); rowData.add(row_data); fireTableDataChanged(); }
public void actionPerformed(ActionEvent e) { List<Resource> loadedDocuments; try { // get all the documents loaded in the system loadedDocuments = Gate.getCreoleRegister().getAllInstances("gate.Document"); } catch (GateException ge) { // gate.Document is not registered in creole.xml....what is!? throw new GateRuntimeException( "gate.Document is not registered in the creole register!\n" + "Something must be terribly wrong...take a vacation!"); } Vector<String> docNames = new Vector<String>(); for (Resource loadedDocument : new ArrayList<Resource>(loadedDocuments)) { if (corpus.contains(loadedDocument)) { loadedDocuments.remove(loadedDocument); } else { docNames.add(loadedDocument.getName()); } } JList docList = new JList(docNames); docList.getSelectionModel().setSelectionInterval(0, docNames.size() - 1); docList.setCellRenderer(renderer); final JOptionPane optionPane = new JOptionPane( new JScrollPane(docList), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); final JDialog dialog = optionPane.createDialog(CorpusEditor.this, "Add document(s) to this corpus"); docList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { optionPane.setValue(JOptionPane.OK_OPTION); dialog.dispose(); } } }); dialog.setVisible(true); if (optionPane.getValue().equals(JOptionPane.OK_OPTION)) { int[] selectedIndices = docList.getSelectedIndices(); for (int selectedIndice : selectedIndices) { corpus.add((Document) loadedDocuments.get(selectedIndice)); } } changeMessage(); }
/** Update a message */ public void updateData(SOAPMonitorData soap) { int row; if (filter_data == null) { // No filter, so just fire table updated row = data.indexOf(soap); if (row != -1) { fireTableRowsUpdated(row, row); } } else { // Check if the row was being displayed row = filter_data.indexOf(soap); if (row == -1) { // Row was not displayed, so check for if it // now needs to be displayed if (filterMatch(soap)) { int index = -1; row = data.indexOf(soap) + 1; while ((row < data.size()) && (index == -1)) { index = filter_data.indexOf(data.elementAt(row)); if (index != -1) { // Insert at this location filter_data.add(index, soap); } row++; } if (index == -1) { // Insert at end index = filter_data.size(); filter_data.addElement(soap); } fireTableRowsInserted(index, index); } } else { // Row was displayed, so check if it needs to // be updated or removed if (filterMatch(soap)) { fireTableRowsUpdated(row, row); } else { filter_data.remove(soap); fireTableRowsDeleted(row, row); } } } }
/** Reaction to Add/Delete buttons. */ public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmdAdd.equals(cmd)) { Zone z = ((ControllerSWARM) controller).new Zone(); Vector<AbstractNetworkElement> ml = ((AbstractControllerComplex) controller).getMyMonitor().getPredecessors(); Vector<AbstractNetworkElement> cl = ((AbstractControllerComplex) controller).getMyMonitor().getSuccessors(); if (ml.size() > 0) z.bottleneck = (AbstractLinkHWC) ml.firstElement(); if (cl.size() > 0) { z.setFromOnramp((AbstractLinkHWC) cl.firstElement()); z.setToOnramp((AbstractLinkHWC) cl.firstElement()); } z.initialize(); zones.add(z); zoneTM.fireTableStructureChanged(); setUpBottleneckColumn(); setUpFromOnrampColumn(); setUpToOnrampColumn(); } if (cmdDelete.equals(cmd)) { try { int[] selected = zonetab.getSelectedRows(); if ((selected != null) && (selected.length > 0)) for (int i = 0; i < selected.length; i++) { int idx = selected[i] - i; if ((idx >= 0) && (idx < zones.size())) { zones.remove(idx); zoneTM.fireTableStructureChanged(); setUpBottleneckColumn(); setUpFromOnrampColumn(); setUpToOnrampColumn(); } } } catch (Exception ex) { } } return; }
public SkelPropTableModel() { m_props.add(new SkeletonProperty()); }
public SkelPropTableModel(SkeletonProperty[] props) { for (int i = 0; i < props.length; i++) { m_props.add(props[i]); } }
/** Fills the panel with SWARM specific fields. */ public void fillPanel() { // Zone initialization ControllerSWARM z = (ControllerSWARM) controller; Vector<Zone> cz = z.zones; for (int i = 0; i < cz.size(); i++) zones.add(cz.get(i).clone()); // Parameter initialization density_sample_size = z.P.SWARM_DENSITY_SAMPLE_SIZE; epsilon = z.P.epsilon; forecast_lead_time = z.P.SWARM_FORECAST_LEAD_TIME; input_var_lane = z.P.input_var_lane; meas_var_lane = z.P.meas_var_lane; phi = z.P.swarm_phi; psi = z.P.swarm_psi; sat_den_multiplier = z.P.SWARM_SAT_DEN_NUMBER; sat_smoother = z.P.sat_smoother; slope_sample_size = z.P.SWARM_SLOPE_SAMPLE_SIZE; // Components JPanel comp = new JPanel(new FlowLayout()); comp.setBorder(BorderFactory.createTitledBorder("Components")); cbsw1.setSelected(z.P.SWARM1); comp.add(cbsw1); comp.add(new JLabel(" ")); cbsw2a.setSelected(z.P.SWARM2A); comp.add(cbsw2a); comp.add(new JLabel(" ")); cbsw2b.setSelected(z.P.SWARM2B); comp.add(cbsw2b); comp.add(new JLabel(" ")); cbdynbott.setEnabled(false); comp.add(cbdynbott); add(comp); // Zones JPanel zone = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); zone.setBorder(BorderFactory.createTitledBorder("Zones")); zonetab.setPreferredScrollableViewportSize(new Dimension(400, 30)); setUpBottleneckColumn(); setUpFromOnrampColumn(); setUpToOnrampColumn(); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 45; c.weightx = 0.5; c.gridwidth = 3; c.gridx = 0; c.gridy = 0; zone.add(new JScrollPane(zonetab), c); c.ipady = 0; c.gridy = 1; c.gridwidth = 1; c.gridx = 0; zone.add(buttonAdd, c); c.gridx = 1; zone.add(buttonDelete, c); // configure buttons buttonAdd.setEnabled(true); buttonAdd.setActionCommand(cmdAdd); buttonAdd.addActionListener(this); buttonDelete.setEnabled(true); buttonDelete.setActionCommand(cmdDelete); buttonDelete.addActionListener(this); add(zone); // Parameters JPanel param = new JPanel(new GridLayout(1, 0)); param.setBorder(BorderFactory.createTitledBorder("Parameters")); final JTable paramtab = new JTable(paramTM); paramtab.setPreferredScrollableViewportSize(new Dimension(500, 160)); param.add(new JScrollPane(paramtab)); add(param); return; }
/** Register a new listener of document change events. */ public void addDocumentChangeListener(DocumentChangeListener l) { if (l != null && !dc_listeners.contains(l)) dc_listeners.add(l); }
/** Fills the panel with simple signal specific fields. */ protected void fillPanel() { if (controller != null) { Vector<CycleDataRow> cd = ((ControllerSimpleSignal) controller).getCycleTable(); for (int i = 0; i < cd.size(); i++) { CycleDataRow cdr = ((ControllerSimpleSignal) controller) .new CycleDataRow(cd.get(i).getTime(), cd.get(i).getGreen(), cd.get(i).getRed()); cycledata.add(cdr); } } // offset JPanel pO = new JPanel(new BorderLayout()); pO.setBorder(BorderFactory.createTitledBorder("Offset (sec.)")); offset = new JSpinner( new SpinnerNumberModel( ((ControllerSimpleSignal) controller).getOffset() * conversion, 0.0, 99999.99, 10)); offset.setEditor(new JSpinner.NumberEditor(offset, "####0.##")); pO.add(offset); add(pO); // table JPanel tabpanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); tabpanel.setBorder(BorderFactory.createTitledBorder("Cycle Schedule")); cycletable = new JTable(cycletablemodel); cycletable.setPreferredScrollableViewportSize(new Dimension(200, 50)); cycletable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int row = cycletable.rowAtPoint(new Point(e.getX(), e.getY())); if ((row > cycledata.size() - 1) || (row < 0)) return; try { WindowEdit winEdit = new WindowEdit(null, cycledata.get(row)); winEdit.setVisible(true); cycletablemodel.deleterow(row); cycletablemodel.addrow(winEdit.getMyRow()); } catch (Exception excp) { } } } }); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 100; c.weightx = 0.5; c.gridwidth = 3; c.gridx = 0; c.gridy = 0; tabpanel.add(new JScrollPane(cycletable), c); c.ipady = 0; c.gridy = 1; c.gridwidth = 1; c.gridx = 0; tabpanel.add(buttonAdd, c); c.gridx = 1; tabpanel.add(buttonDelete, c); add(tabpanel); // configure buttons buttonAdd.setEnabled(true); buttonAdd.addActionListener(new ButtonAddListener()); buttonDelete.setEnabled(true); buttonDelete.addActionListener(new ButtonDeleteListener()); return; }
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (timeList != null) { if (rowIndex < timeList.size()) timeList.setElementAt(aValue, rowIndex); else timeList.add(aValue); } }