List of usage examples for javax.swing.table DefaultTableModel DefaultTableModel
public DefaultTableModel(Object[][] data, Object[] columnNames)
DefaultTableModel
and initializes the table by passing data
and columnNames
to the setDataVector
method. From source file:Vista.VentasCliente.java
private void jButton_executeSpecificVCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_executeSpecificVCActionPerformed // TODO add your handling code here: String[] respuesta = client.consultaGeneralCliente("0;" + jTextField_NombreCliente.getText(), "") .split(";"); String[] nombres = { "Nombre", "Numero de Contacto", "Empresa", "Numero de facturas" }; DefaultTableModel dtm = new DefaultTableModel(nombres, respuesta.length); dtm = (DefaultTableModel) this.jTable_ConsultaParticularlCliente.getModel(); this.jTable_ConsultaGeneralCliente.removeAll(); for (String s : respuesta) { String[] columnasT = s.split("\\t"); dtm.addRow(new Object[] { columnasT[1], columnasT[2], columnasT[3], columnasT[4] }); }//from www. j a v a 2 s. co m }
From source file:Vista.CuentasCobrar.java
private void jButton_EjecuteCXC1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_EjecuteCXC1ActionPerformed // TODO add your handling code here: String[] resp = client.consultarCuentas("0;0", jTextField_Ciudad.getText().trim()).split("\\n"); String[] nombres = { "Nombre", "Numero de Contacto", "Empresa", "Numero de facturas" }; DefaultTableModel dtm = new DefaultTableModel(nombres, resp.length); dtm = (DefaultTableModel) this.jTable_CuentasPorCobrar.getModel(); this.jTable_CuentasPorCobrar.removeAll(); for (String s : resp) { String[] columnasT = s.split("\\t"); dtm.addRow(new Object[] { columnasT[1], columnasT[2], columnasT[3], columnasT[4] }); }/*from w w w.j a va 2 s . c om*/ }
From source file:archive_v1.Retrieve.java
private void tapeId_tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tapeId_tableMouseClicked // TODO add your handling code here: Vector columnNames = new Vector(); Vector data = new Vector(); int columns = 0; String tape_id = tapeId_table.getModel().getValueAt(tapeId_table.getSelectedRow(), 0).toString(); String sql = "", archive_date = "", archiver_name = ""; create_archive_connection();//from ww w.j av a 2s.c o m try { statement_archive = conn_archive.createStatement(); sql = "select * from archive where tape_id = '" + tape_id + "'"; rs_archive = statement_archive.executeQuery(sql); columnNames.addElement("File Name"); columnNames.addElement("size(bytes)"); // Get row data while (rs_archive.next()) { Vector row = new Vector(columns); row.addElement(rs_archive.getString("program_name")); row.addElement(rs_archive.getString("size")); archive_date = rs_archive.getString("archive_date"); archiver_name = rs_archive.getString("archiver_name"); data.addElement(row); } // populated data into table DefaultTableModel tableModel = new DefaultTableModel(data, columnNames); pgmList_table.setModel(tableModel); archive_date_label.setText(archive_date); archiever_name_label.setText(archiver_name); // this.pgmList_table.setModel(DbUtils.resultSetToTableModel(rs_archive)); } catch (Exception e) { e.printStackTrace(); } finally { try { conn_archive.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java
/** * /*from ww w . j av a 2s . c om*/ */ private void showUsersLoggedIn() { String sql = " SELECT Name, IsLoggedIn, IsLoggedInReport, LoginCollectionName, LoginDisciplineName FROM specifyuser WHERE IsLoggedIn <> 0"; Vector<Object[]> dataRows = BasicSQLUtils.query(sql); Object[][] data = new Object[dataRows.size()][5]; for (int i = 0; i < dataRows.size(); i++) { data[i] = dataRows.get(i); } DefaultTableModel model = new DefaultTableModel(data, new Object[] { "User", "Is Logged In", "Is Logged In to Report", "Login Collection", "Login Discipline" }); JTable table = new JTable(model); UIHelper.makeTableHeadersCentered(table, true); JScrollPane scrollPane = UIHelper.createScrollPane(table); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); CustomDialog infoDlg = new CustomDialog((Dialog) null, "Users Logged In", true, CustomDialog.OK_BTN, panel); infoDlg.setCancelLabel("Close"); infoDlg.createUI(); infoDlg.setSize(600, 300); infoDlg.setVisible(true); }
From source file:Vista.VentasCliente.java
private void jButton_executeGeneralVCl_CiudadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_executeGeneralVCl_CiudadActionPerformed String[] respuesta = client// w ww . ja va 2s . co m .consultaGeneralCliente("0;" + jTextField_NombreCliente.getText(), jTextField_City.getText().trim()) .split(";"); String[] nombres = { "Nombre", "Numero de Contacto", "Empresa", "Numero de facturas" }; DefaultTableModel dtm = new DefaultTableModel(nombres, respuesta.length); dtm = (DefaultTableModel) this.jTable_ConsultaParticularlCliente.getModel(); this.jTable_ConsultaGeneralCliente.removeAll(); for (String s : respuesta) { String[] columnasT = s.split("\\t"); dtm.addRow(new Object[] { columnasT[1], columnasT[2], columnasT[3], columnasT[4] }); } }
From source file:edu.harvard.i2b2.patientMapping.ui.PatientMappingJPanel.java
private void jImportButtonActionPerformed(java.awt.event.ActionEvent evt) { Display.getDefault().syncExec(new Runnable() { public void run() { String fileName = openFileDialog(); //if (fileName != null) { //String fileName = dialog.getFileName(); if (fileName != null && fileName.trim().length() > 0) { log.info("Selected file: " + fileName); FileReader fr;/* ww w . j a v a 2 s .c om*/ BufferedReader br = null; try { fr = new FileReader(new File(fileName)); br = new BufferedReader(fr); String line = br.readLine(); //if(!line.startsWith("@@i2b2 patient mapping file@@")) { // java.awt.EventQueue.invokeLater(new Runnable() { // public void run() { //setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); // JOptionPane.showMessageDialog(jLabel1, "The file is not in a valid format.", "Error importing", JOptionPane.ERROR_MESSAGE); // } // }); //JOptionPane.showMessageDialog(null, "The file is not a valid.", "Error importing", JOptionPane.ERROR_MESSAGE); // return; //} //line = br.readLine(); log.info("column name: " + line); String[] cols = line.split(","); DefaultTableModel model = new DefaultTableModel(cols, 200) { @Override public boolean isCellEditable(int arg0, int arg1) { return false; } }; //{ //@SuppressWarnings("unchecked") //Class[] types = new Class[] { java.lang.Boolean.class, //java.lang.String.class }; //@SuppressWarnings("unchecked") //public Class getColumnClass(int columnIndex) { //if(columnIndex ==0) { //return java.lang.Boolean.class; //} //return java.lang.Object.class; //} // }; jTable1.setModel(model); String[] row; int rowCount = 0; line = br.readLine(); while (line != null) { log.info(line); row = line.split(","); String id = ""; for (int i = 0; i < row.length; i++) { id = row[i]; //if(cols[i].indexOf("_E") > 0) { //////id = decryptID(id); //} //decryptID(row[i]); jTable1.setValueAt(id, rowCount, i); } rowCount++; line = br.readLine(); } model.setRowCount(rowCount); br.close(); } catch (Exception e) { e.printStackTrace(); if (br != null) { try { br.close(); } catch (Exception e1) { } } } } //} } }); }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
public void makeFilterTable() { filterTable = new MirthTable(); filterTable.setModel(new DefaultTableModel(new String[] { "#", "Operator", "Name", "Type", "Data" }, 0) { public boolean isCellEditable(int rowIndex, int columnIndex) { boolean[] canEdit; FilterRulePlugin plugin;/*from ww w .ja va2 s.c o m*/ try { plugin = getPlugin((String) filterTableModel.getValueAt(rowIndex, RULE_TYPE_COL)); canEdit = new boolean[] { false, true, plugin.isNameEditable(), true, true }; } catch (Exception e) { canEdit = new boolean[] { false, true, true, true, true }; } return canEdit[columnIndex]; } }); filterTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); filterTableModel = (DefaultTableModel) filterTable.getModel(); filterTable.getColumnModel().getColumn(RULE_NAME_COL).setCellEditor(new EditorTableCellEditor(this)); filterTable.setCustomEditorControls(true); // Set the combobox editor on the operator column, and add action // listener MirthComboBoxTableCellEditor comboBoxOp = new MirthComboBoxTableCellEditor(filterTable, comboBoxValues, 2, true, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { modified = true; updateOperations(); } }); // Set the combobox editor on the type column, and add action listener String[] defaultComboBoxValues = new String[LoadedExtensions.getInstance().getFilterRulePlugins().size()]; FilterRulePlugin[] pluginArray = LoadedExtensions.getInstance().getFilterRulePlugins().values() .toArray(new FilterRulePlugin[0]); for (int i = 0; i < pluginArray.length; i++) { defaultComboBoxValues[i] = pluginArray[i].getPluginPointName(); } MirthComboBoxTableCellEditor comboBoxType = new MirthComboBoxTableCellEditor(filterTable, defaultComboBoxValues, 2, true, new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (filterTable.getEditingRow() != -1) { int row = getSelectedRow(); String selectedType = ((JComboBox) evt.getSource()).getSelectedItem().toString(); String previousType = (String) filterTable.getValueAt(row, RULE_TYPE_COL); if (selectedType.equalsIgnoreCase(previousType)) { return; } modified = true; FilterRulePlugin plugin; try { if (rulePanel.isModified() && !PlatformUI.MIRTH_FRAME.alertOption( PlatformUI.MIRTH_FRAME, "Are you sure you would like to change this filter rule and lose all of the current filter data?")) { ((JComboBox) evt.getSource()).getModel().setSelectedItem(previousType); return; } plugin = getPlugin(selectedType); plugin.initData(); filterTableModel.setValueAt(plugin.getNewName(), row, RULE_NAME_COL); rulePanel.showCard(selectedType); updateTaskPane(selectedType); updateCodePanel(selectedType); } catch (Exception e) { parent.alertThrowable(parent, e); } } } }); filterTable.setSelectionMode(0); // only select one row at a time filterTable.getColumnExt(RULE_NUMBER_COL).setMaxWidth(UIConstants.MAX_WIDTH); filterTable.getColumnExt(RULE_OP_COL).setMaxWidth(UIConstants.MAX_WIDTH); filterTable.getColumnExt(RULE_NUMBER_COL).setPreferredWidth(30); filterTable.getColumnExt(RULE_OP_COL).setPreferredWidth(60); filterTable.getColumnExt(RULE_NUMBER_COL).setCellRenderer(new CenterCellRenderer()); filterTable.getColumnExt(RULE_OP_COL).setCellEditor(comboBoxOp); filterTable.getColumnExt(RULE_OP_COL).setCellRenderer(new MirthComboBoxTableCellRenderer(comboBoxValues) { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value instanceof String && value.equals("")) { value = null; } else if (value != null) { value = value.toString(); } return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } }); filterTable.getColumnExt(RULE_TYPE_COL).setMaxWidth(UIConstants.MAX_WIDTH); filterTable.getColumnExt(RULE_TYPE_COL).setMinWidth(120); filterTable.getColumnExt(RULE_TYPE_COL).setPreferredWidth(120); filterTable.getColumnExt(RULE_TYPE_COL).setCellEditor(comboBoxType); filterTable.getColumnExt(RULE_TYPE_COL) .setCellRenderer(new MirthComboBoxTableCellRenderer(defaultComboBoxValues)); filterTable.getColumnExt(RULE_DATA_COL).setVisible(false); filterTable.setRowHeight(UIConstants.ROW_HEIGHT); filterTable.packTable(UIConstants.COL_MARGIN); filterTable.setSortable(false); filterTable.setOpaque(true); filterTable.setRowSelectionAllowed(true); filterTable.setDragEnabled(false); filterTable.getTableHeader().setReorderingAllowed(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); filterTable.setHighlighters(highlighter); } filterTable.setDropTarget(dropTarget); filterTablePane.setDropTarget(dropTarget); filterTable.setBorder(BorderFactory.createEmptyBorder()); filterTablePane.setBorder(BorderFactory.createEmptyBorder()); filterTablePane.setViewportView(filterTable); filterTable.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { checkSelectionAndPopupMenu(evt); } public void mouseReleased(MouseEvent evt) { checkSelectionAndPopupMenu(evt); } }); filterTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (!updating && !evt.getValueIsAdjusting()) { FilterListSelected(evt); updateCodePanel(null); } } }); filterTable.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { deleteRule(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); }
From source file:gtu._work.ui.PropertyEditUI.java
private void initGUI() { try {/*from www . j a v a 2 s. c o m*/ setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); BorderLayout thisLayout = new BorderLayout(); this.setTitle("PropertyEditUI"); getContentPane().setLayout(thisLayout); { jMenuBar1 = new JMenuBar(); setJMenuBar(jMenuBar1); { jMenu1 = new JMenu(); jMenuBar1.add(jMenu1); jMenu1.setText("File"); { jMenuItem1 = new JMenuItem(); jMenu1.add(jMenuItem1); jMenuItem1.setText("open directory"); jMenuItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JCommonUtil._jFileChooser_selectDirectoryOnly(); loadCurrentFile(file); } }); } { openDirectoryAndChildren = new JMenuItem(); jMenu1.add(openDirectoryAndChildren); openDirectoryAndChildren.setText("open directory and children"); openDirectoryAndChildren.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("openDirectoryAndChildren.actionPerformed, event=" + evt); File file = JCommonUtil._jFileChooser_selectDirectoryOnly(); if (file == null) { // file = // PropertiesUtil.getJarCurrentPath(getClass());//XXX file = new File("D:\\my_tool\\english"); JCommonUtil._jOptionPane_showMessageDialog_info("load C:\\L-CONFIG !"); } DefaultListModel model = new DefaultListModel(); List<File> list = new ArrayList<File>(); FileUtil.searchFileMatchs(file, ".*\\.properties", list); for (File f : list) { File_ ff = new File_(); ff.file = f; model.addElement(ff); } backupFileList = list; fileList.setModel(model); } }); } { jMenuItem2 = new JMenuItem(); jMenu1.add(jMenuItem2); jMenuItem2.setText("save"); jMenuItem2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("jMenu3.actionPerformed, event=" + evt); if (currentFile == null) { return; } if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "save to " + currentFile.getName(), "SAVE")) { try { Properties prop = new Properties(); // try { // prop.load(new // FileInputStream(currentFile)); // } catch (Exception e) { // e.printStackTrace(); // JCommonUtil.handleException(e); // return; // } loadModelToProperties(prop); prop.store(new FileOutputStream(currentFile), getTitle()); } catch (Exception e) { e.printStackTrace(); JCommonUtil.handleException(e); } } } }); } { jMenuItem3 = new JMenuItem(); jMenu1.add(jMenuItem3); jMenuItem3.setText("save to target"); jMenuItem3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog() .getApproveSelectedFile(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error("file name is not correct!"); return; } if (!file.getName().contains(".properties")) { file = new File(file.getParent(), file.getName() + ".properties"); } try { Properties prop = new Properties(); // try { // prop.load(new // FileInputStream(currentFile)); // } catch (Exception e) { // e.printStackTrace(); // JCommonUtil.handleException(e); // return; // } loadModelToProperties(prop); prop.store(new FileOutputStream(file), getTitle()); } catch (Exception e) { e.printStackTrace(); JCommonUtil.handleException(e); } } }); } { jMenuItem4 = new JMenuItem(); jMenu1.add(jMenuItem4); jMenuItem4.setText("save file(sorted)"); jMenuItem4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (currentFile == null) { return; } try { BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(currentFile))); List<String> sortList = new ArrayList<String>(); for (String line = null; (line = reader.readLine()) != null;) { sortList.add(line); } reader.close(); Collections.sort(sortList); StringBuilder sb = new StringBuilder(); for (String line : sortList) { sb.append(line + "\n"); } FileUtil.saveToFile(currentFile, sb.toString(), "UTF8"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }); } { jMenuItem5 = new JMenuItem(); jMenu1.add(jMenuItem5); jMenuItem5.setText(""); jMenuItem5.addActionListener(new ActionListener() { private void setMeaning(String meaning, int rowPos) { propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2); } private void setMeaningEn1(String english, int rowPos, List<String> errSb) { EnglishTester_Diectory eng = new EnglishTester_Diectory(); try { WordInfo wordInfo = eng.parseToWordInfo(english); String meaning = getChs2Big5(wordInfo.getMeaning()); if (hasChinese(meaning)) { setMeaning(meaning, rowPos); } else { setMeaningEn2(english, rowPos, errSb); } } catch (Exception e) { errSb.add(english); e.printStackTrace(); } } private void setMeaningEn2(String english, int rowPos, List<String> errSb) { EnglishTester_Diectory2 eng2 = new EnglishTester_Diectory2(); try { WordInfo2 wordInfo = eng2.parseToWordInfo(english); String meaning = getChs2Big5(StringUtils.join(wordInfo.getMeaningList(), ";")); setMeaning(meaning, rowPos); } catch (Exception e) { errSb.add(english); e.printStackTrace(); } } private boolean hasChinese(String val) { return new StringUtil_().getChineseWord(val, true).length() > 0; } private Properties loadFromMemoryBank() { try { Properties prop = new Properties(); File f1 = new File( "D:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties"); File f2 = new File( "e:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties"); for (File f : new File[] { f1, f2 }) { if (f.exists()) { HermannEbbinghaus_Memory memory = new HermannEbbinghaus_Memory(); memory.init(f); List<MemData> memLst = memory.getAllMemData(true); for (MemData d : memLst) { prop.setProperty(d.getKey(), getChs2Big5(d.getRemark())); } break; } } return prop; } catch (Exception ex) { throw new RuntimeException(ex); } } public void actionPerformed(ActionEvent evt) { if (currentFile == null) { return; } // Properties memoryProp = loadFromMemoryBank(); Properties memoryProp = new Properties(); List<String> errSb = new ArrayList<String>(); for (int row = 0; row < propTable.getModel().getRowCount(); row++) { int rowPos = propTable.getRowSorter().convertRowIndexToModel(row); String english = StringUtils.trimToEmpty( (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1)) .toLowerCase(); String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 2); if (memoryProp.containsKey(english) && StringUtils.isNotBlank(memoryProp.getProperty(english))) { setMeaning(memoryProp.getProperty(english), rowPos); } else { if (StringUtils.isBlank(desc) || !hasChinese(desc)) { if (!english.contains(" ")) { setMeaningEn1(english, rowPos, errSb); } else { setMeaningEn2(english, rowPos, errSb); } } } if (StringUtils.trimToEmpty(desc).contains("?")) { setMeaning("", rowPos); } } if (!errSb.isEmpty()) { JCommonUtil._jOptionPane_showMessageDialog_error(":\n" + errSb); } } }); } { JMenuItem jMenuItem6 = new JMenuItem(); jMenu1.add(jMenuItem6); jMenuItem6.setText(""); jMenuItem6.addActionListener(new ActionListener() { private void setMeaning(String meaning, int rowPos) { propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2); } public void actionPerformed(ActionEvent evt) { for (int row = 0; row < propTable.getModel().getRowCount(); row++) { int rowPos = propTable.getRowSorter().convertRowIndexToModel(row); String english = StringUtils.trimToEmpty( (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1)) .toLowerCase(); String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 2); if (StringUtils.trimToEmpty(desc).contains("?")) { setMeaning("", rowPos); } } } }); } } } { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("editor", null, jPanel2, null); { jScrollPane1 = new JScrollPane(); jPanel2.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(550, 314)); { TableModel propTableModel = new DefaultTableModel( new String[][] { { "", "", "" }, { "", "", "" } }, new String[] { "index", "Key", "value" }); propTable = new JTable(); JTableUtil.defaultSetting_AutoResize(propTable); jScrollPane1.setViewportView(propTable); propTable.setModel(propTableModel); propTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JTableUtil xxxxxx = JTableUtil.newInstance(propTable); int[] rows = xxxxxx.getSelectedRows(); for (int ii : rows) { System.out.println(xxxxxx.getModel().getValueAt(ii, 1)); } JPopupMenuUtil.newInstance(propTable).applyEvent(evt) .addJMenuItem(JTableUtil.newInstance(propTable).getDefaultJMenuItems()) .show(); } }); } } { queryText = new JTextField(); jPanel2.add(queryText, BorderLayout.NORTH); queryText.getDocument() .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() { @Override public void process(DocumentEvent event) { if (currentFile == null) { return; } Properties prop = new Properties(); try { prop.load(new FileInputStream(currentFile)); } catch (Exception e) { e.printStackTrace(); JCommonUtil.handleException(e); return; } loadPropertiesToModel(prop); String text = JCommonUtil.getDocumentText(event); Pattern pattern = null; try { pattern = Pattern.compile(text); } catch (Exception ex) { } DefaultTableModel model = JTableUtil.newInstance(propTable).getModel(); for (int ii = 0; ii < model.getRowCount(); ii++) { String key = (String) model.getValueAt(ii, 1); String value = (String) model.getValueAt(ii, 2); if (key.contains(text)) { continue; } if (value.contains(text)) { continue; } if (pattern != null) { if (pattern.matcher(key).find()) { continue; } if (pattern.matcher(value).find()) { continue; } } model.removeRow(propTable.convertRowIndexToModel(ii)); ii--; } } })); } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("folder", null, jPanel3, null); { jScrollPane2 = new JScrollPane(); jPanel3.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(550, 314)); { fileList = new JList(); jScrollPane2.setViewportView(fileList); fileList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(fileList).defaultJListKeyPressed(evt); } }); fileList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { final File_ file = JListUtil.getLeadSelectionObject(fileList); if (evt.getButton() == MouseEvent.BUTTON1) { Properties prop = new Properties(); currentFile = file.file; setTitle(currentFile.getName()); try { prop.load(new FileInputStream(file.file)); } catch (Exception e) { e.printStackTrace(); } loadPropertiesToModel(prop); } if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) { try { Runtime.getRuntime().exec(String.format("cmd /c \"%s\"", file.file)); } catch (IOException e1) { e1.printStackTrace(); } } final File parent = file.file.getParentFile(); JMenuItem openTargetDir = new JMenuItem(); openTargetDir.setText("open : " + parent); openTargetDir.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().open(parent); } catch (IOException e1) { JCommonUtil.handleException(e1); } } }); JPopupMenuUtil.newInstance(fileList).addJMenuItem(openTargetDir).applyEvent(evt) .show(); } }); } } { fileQueryText = new JTextField(); jPanel3.add(fileQueryText, BorderLayout.NORTH); fileQueryText.getDocument() .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() { @Override public void process(DocumentEvent event) { String text = JCommonUtil.getDocumentText(event); DefaultListModel model = new DefaultListModel(); for (File f : backupFileList) { if (f.getName().contains(text)) { File_ ff = new File_(); ff.file = f; model.addElement(ff); } } fileList.setModel(model); } })); } { contentQueryText = new JTextField(); jPanel3.add(contentQueryText, BorderLayout.SOUTH); contentQueryText.addActionListener(new ActionListener() { void addModel(File f, DefaultListModel model) { File_ ff = new File_(); ff.file = f; model.addElement(ff); } public void actionPerformed(ActionEvent evt) { DefaultListModel model = new DefaultListModel(); String text = contentQueryText.getText(); if (StringUtils.isEmpty(contentQueryText.getText())) { return; } Pattern pattern = Pattern.compile(text); Properties pp = null; for (File f : backupFileList) { pp = new Properties(); try { pp.load(new FileInputStream(f)); for (String key : pp.stringPropertyNames()) { if (key.isEmpty()) { continue; } if (pp.getProperty(key) == null || pp.getProperty(key).isEmpty()) { continue; } if (key.contains(text)) { addModel(f, model); break; } if (pp.getProperty(key).contains(text)) { addModel(f, model); break; } if (pattern.matcher(key).find()) { addModel(f, model); break; } if (pattern.matcher(pp.getProperty(key)).find()) { addModel(f, model); break; } } } catch (Exception e) { e.printStackTrace(); } } fileList.setModel(model); } }); } } } JCommonUtil.setJFrameIcon(this, "resource/images/ico/english.ico"); JCommonUtil.setJFrameCenter(this); pack(); this.setSize(571, 408); loadCurrentFile(null); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java
/** * /*from w w w . j a va2s .com*/ */ private void printUserData() { JTable printTable = new JTable(); int i = 0; Object[][] pValueObjs = new Object[userModel.getUserData().size()][6]; for (UserData ud : userModel.getUserData()) { pValueObjs[i++] = ud.getData(); } String[] headers = { "Username", "Passsword", "Last Name", "First Name", "EMail", "New Password" }; DefaultTableModel model = new DefaultTableModel(pValueObjs, headers) { @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } }; printTable.setModel(model); PrintTableHelper pth = new PrintTableHelper(printTable); pth.printGrid(UIRegistry.getResourceString("SUMMARY")); }
From source file:canreg.client.gui.components.PreviewFilePanel.java
/** * */// w w w . j ava2s. c o m @Action public void previewAction() { // show the contents of the file BufferedReader br = null; try { changeFile(); // numberOfRecordsTextField.setText(""+(canreg.common.Tools.numberOfLinesInFile(inFile.getAbsolutePath())-1)); FileInputStream fis = new FileInputStream(inFile); br = new BufferedReader(new InputStreamReader(fis, (Charset) charsetsComboBox.getSelectedItem())); CSVFormat csvFormat = CSVFormat.DEFAULT.withFirstRecordAsHeader().withDelimiter(getSeparator()); CSVParser csvParser = new CSVParser(br, csvFormat); int linesToRead = Globals.NUMBER_OF_LINES_IN_IMPORT_PREVIEW; int numberOfLinesRead = 0; Vector<Vector<String>> data = new Vector<Vector<String>>(); String[] headers = csvParser.getHeaderMap().keySet().toArray(new String[0]); for (CSVRecord csvRecord : csvParser) { csvRecord.toMap(); Vector vec = new Vector(); Iterator<String> iterator = csvRecord.iterator(); while (iterator.hasNext()) { vec.add(iterator.next()); } data.add(vec); numberOfLinesRead++; if (numberOfLinesRead >= linesToRead) { break; } } numberOfRecordsShownTextField.setText(numberOfLinesRead + ""); // previewTextArea.setText(headers + "\n" + dataText); // previewTextArea.setCaretPosition(0); previewPanel.setVisible(true); Vector columnNames = new Vector(Arrays.asList(headers)); previewTable.setModel(new DefaultTableModel(data, columnNames)); } catch (FileNotFoundException fileNotFoundException) { JOptionPane.showInternalMessageDialog(CanRegClientApp.getApplication().getMainFrame().getContentPane(), java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView") .getString("COULD_NOT_PREVIEW_FILE:") + " \'" + fileNameTextField.getText().trim() + "\'.", java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView") .getString("ERROR"), JOptionPane.ERROR_MESSAGE); Logger.getLogger(PreviewFilePanel.class.getName()).log(Level.SEVERE, null, fileNotFoundException); } catch (IOException ex) { Logger.getLogger(PreviewFilePanel.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (br != null) { br.close(); } } catch (IOException ex) { Logger.getLogger(PreviewFilePanel.class.getName()).log(Level.SEVERE, null, ex); } } }