/** * Set the current open DarwinCSV. You should really, really, really setCurrentCSV(null) before * you load a new DarwinCSV. * * @param csv The new DarwinCSV object. */ private void setCurrentCSV(DarwinCSV csv) { // Clear the old currentCSV object and matchAgainst object. currentCSV = null; matchAgainst(null); // Load the new currentCSV object. currentCSV = csv; table.removeAll(); table.setDefaultRenderer(Name.class, this); // Set the currentCSV // TODO: This causes an exception occasionally, because we shouldn't // be calling setModel outside of the Event Queue thread; however, we're // currently in a worker thread, so dipping back into the Event thread // would just cause more problems. Sorry! if (csv != null) { table.setModel(currentCSV.getRowIndex()); } else { table.setModel(blankDataModel); } columnInfoPanel.loadedFileChanged(csv); columnInfoPanel.columnChanged(-1); table.repaint(); }
public void setResultSet(DiskResultSet rset) throws Exception { set = rset; max = rset.getRowCount(); table.setModel(model); table.setModel(this); offset = 0; scrollBar.setValue(0); scrollBar.setMaximum((max < window ? 0 : max - window)); }
stab(ResultSet k) { super("PATIENT FOUND"); String[] chd = { "Date", "Patient ID", "Name", "Gender", "Age", "Weight", "Address", "Contact No.", "Doctor Name", "Symptoms", "Dignosis", "Fee: Rs.", "Blood Group" }; // DefaultTableModel dtm=new DefaultTableModel(); // jt.setModel(new DefaultTableModel(arr,chd)); jt = new JTable(); jsp = new JScrollPane(jt); btn = new JButton("CLOSE"); btn.addActionListener(this); int i = 0; try { while (k.next()) { arr[i][0] = k.getString(1); // System.out.println("ddddddddddddd"+arr[i][0]); arr[i][1] = "" + k.getInt(2); arr[i][2] = k.getString(3) + " " + k.getString(4) + " " + k.getString(5); arr[i][3] = k.getString(6); arr[i][4] = "" + k.getInt(7); arr[i][5] = k.getString(8); arr[i][6] = k.getString(9); arr[i][7] = k.getString(10); arr[i][8] = k.getString(11); arr[i][9] = k.getString(12); arr[i][10] = k.getString(13); arr[i][11] = "" + k.getInt(14); arr[i][12] = k.getString(15); arr[i][13] = k.getString(16); // dtm.insertRow(i,new Object[]{patient.rs.getString(1), // patient.rs.getInt(2),patient.rs.getString(3)+patient.rs.getString(4)+patient.rs.getString(5),patient.rs.getString(6),patient.rs.getInt(7),patient.rs.getString(8),patient.rs.getString(9),patient.rs.getString(10),patient.rs.getString(11),patient.rs.getString(12),patient.rs.getString(13),patient.rs.getInt(14)}); i++; } } catch (Exception e12) { System.out.println("" + e12); } jt.setModel(new DefaultTableModel(arr, chd)); Container con = getContentPane(); con.setLayout(null); jsp.setBounds(20, 20, 1230, 600); btn.setBounds(685, 630, 100, 30); add(jsp); add(btn); setSize(1330, 800); setVisible(true); }
public void setMetricsResults(MetricDisplaySpecification displaySpecification, MetricsRun run) { final MetricCategory[] categories = MetricCategory.values(); for (final MetricCategory category : categories) { final JTable table = tables.get(category); final String type = MetricsCategoryNameUtil.getShortNameForCategory(category); final MetricTableSpecification tableSpecification = displaySpecification.getSpecification(category); final MetricsResult results = run.getResultsForCategory(category); final MetricTableModel model = new MetricTableModel(results, type, tableSpecification); table.setModel(model); final Container tab = table.getParent().getParent(); if (model.getRowCount() == 0) { tabbedPane.remove(tab); continue; } final String longName = MetricsCategoryNameUtil.getLongNameForCategory(category); tabbedPane.add(tab, longName); final MyColumnListener columnListener = new MyColumnListener(tableSpecification, table); final TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(columnListener); final int columnCount = columnModel.getColumnCount(); for (int i = 0; i < columnCount; i++) { final TableColumn column = columnModel.getColumn(i); column.addPropertyChangeListener(columnListener); } setRenderers(table, type); setColumnWidths(table, tableSpecification); } }
@Override public void setModel(final TableModel model) { super.setModel(model); if (model instanceof SortableColumnModel) { final SortableColumnModel sortableModel = (SortableColumnModel) model; if (sortableModel.isSortable()) { final TableRowSorter<TableModel> rowSorter = createRowSorter(model); rowSorter.setSortsOnUpdates(isSortOnUpdates()); setRowSorter(rowSorter); final RowSorter.SortKey sortKey = sortableModel.getDefaultSortKey(); if (sortKey != null && sortKey.getColumn() >= 0 && sortKey.getColumn() < model.getColumnCount()) { if (sortableModel.getColumnInfos()[sortKey.getColumn()].isSortable()) { rowSorter.setSortKeys(Arrays.asList(sortKey)); } } } else { final RowSorter<? extends TableModel> rowSorter = getRowSorter(); if (rowSorter instanceof DefaultColumnInfoBasedRowSorter) { setRowSorter(null); } } } }
@SuppressWarnings("unchecked") private JComponent jRoom() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createTitledBorder("")); scrollPane = new JScrollPane(); jRoom = new JTable(); tableTitle.add("RoomID"); tableTitle.add("RoomNumber"); tableTitle.add("RoomType"); tableTitle.add("NumBeds"); tableTitle.add("RoomTypeRate"); tableTitle.add("RoomStatus"); tableTitle.add("Description"); model = new DefaultTableModel(tableRecords, tableTitle) { private static final long serialVersionUID = 1L; public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; jRoom.setModel(model); jRoom.getTableHeader().setReorderingAllowed(false); scrollPane.setViewportView(jRoom); panel.add(scrollPane); return panel; }
public void updateActionTableFor(EditorClient client) { if (client == null) { DefaultTableModel model = new DefaultTableModel(); tblActions.setModel(getClearTableModel()); return; } else if (currClient == client) { DefaultTableModel model = getClearTableModel(); Iterator i = client.getActions(self).iterator(); while (i.hasNext()) { EditorAction ea = (EditorAction) i.next(); model.addRow(ea.getTableRow()); } tblActions.setModel(model); } }
private void backBind() { status.setText(viewModel.getStatus()); compute.setEnabled(viewModel.isButtonEnabled()); monthlyPayment.setText(viewModel.getMonthlyPayment()); overpaymentWithFees.setText(viewModel.getOverpaymentWithFees()); overpayment.setText(viewModel.getOverpayment()); DefaultTableModel model = viewModel.getGraphicOfPayments(); graphicOfPayments.setModel(model); graphicOfPayments.setPreferredSize( new Dimension( graphicOfPayments.getWidth(), graphicOfPayments.getRowHeight() * model.getRowCount())); List<String> log = viewModel.getLog(); String[] items = log.toArray(new String[log.size()]); logList.setListData(items); }
/** Initial method to populate the insuranceCompaniesTable */ public void loadTable() { Map<Integer, InsuranceCompany> data = model.getInsuranceCompanies(); tableData = new InsuranceCompanyTableModel(data); insuranceCompaniesTable.setModel(tableData); insuranceCompaniesTable.getColumnModel().getColumn(0).setMaxWidth(50); insuranceCompaniesTable .getSelectionModel() .setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Check if db is empty and proceed with selecting only if the table is populated if (insuranceCompaniesTable.getRowCount() > 0) { // Set selected company according to selected row on load selectRow(); int selectedCompanyId = Integer.valueOf( (String) insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0)); } }
/** Create a new, empty property sheet. */ public PropertySheet() { super(new EnhancedTable()); this.getPreferredSize(); props = new ForClassPropertyList(); // Add bean change event listener props.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { // XXX Should I fire a 'stop editing' event here? refresh(); } }); // Add table JTable table = getTable(); MyTableModel tableModel = new MyTableModel(); table.setModel(tableModel); table.setDefaultRenderer(InstancePropertyDescriptor.class, new MyCellRenderer()); table.setDefaultEditor(InstancePropertyDescriptor.class, new MyCellEditor()); }
public static void main(String[] xx) { JFrame fr = new JFrame("belajar table"); MahasiswaTableModel model = new MahasiswaTableModel(data); model.addTableModelListener(new TabelDiubahListener()); tabel.setModel(model); tabel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tabel.getSelectionModel().addListSelectionListener(new TabelDipilihListener()); JScrollPane scrTabel = new JScrollPane(tabel); JTextArea txtOutput = new JTextArea(5, 20); JScrollPane scrText = new JScrollPane(txtOutput); fr.getContentPane().add(scrText, BorderLayout.SOUTH); fr.getContentPane().add(scrTabel, BorderLayout.CENTER); fr.setSize(600, 600); fr.setLocationRelativeTo(null); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fr.setVisible(true); }
private void jbInit() throws Exception { panel1.setLayout(borderLayout1); okButton.setText("OK"); okButton.addActionListener(new MimeTypeEditor_okButton_actionAdapter(this)); filtersTable.setRowSelectionAllowed(true); filtersTable.setPreferredSize(new Dimension(418, 200)); filtersTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); filtersTable.setCellSelectionEnabled(true); filtersTable.setColumnSelectionAllowed(false); filtersTable.setModel(m_model); addButton.setToolTipText( "Add a new " + mimeTypeEditorBuilder.getValueName() + " for a MIME type"); addButton.setText("Add"); addButton.addActionListener(new MimeTypeEditor_addButton_actionAdapter(this)); cancelButton.setText("Cancel"); cancelButton.addActionListener(new MimeTypeEditor_cancelButton_actionAdapter(this)); deleteButton.setToolTipText("Delete the currently selected item."); deleteButton.setText("Delete"); deleteButton.addActionListener(new MimeTypeEditor_deleteButton_actionAdapter(this)); upButton.setText("Up"); upButton.addActionListener(new MimeTypeEditor_upButton_actionAdapter(this)); dnButton.setText("Down"); dnButton.addActionListener(new MimeTypeEditor_dnButton_actionAdapter(this)); panel1.setPreferredSize(new Dimension(418, 200)); jScrollPane1.setMinimumSize(new Dimension(200, 80)); jScrollPane1.setOpaque(true); buttonPanel.add(dnButton, null); buttonPanel.add(upButton, null); buttonPanel.add(addButton, null); buttonPanel.add(deleteButton, null); buttonPanel.add(okButton, null); buttonPanel.add(cancelButton, null); getContentPane().add(panel1); panel1.add(buttonPanel, BorderLayout.SOUTH); panel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(filtersTable, null); }
// ambil data dari database untuk tabel public void setDataTabel() { // combobox jenis JComboBox cbJenis = new JComboBox(); cbJenis.setModel(new DefaultComboBoxModel(dataJenis.toArray())); dataProduk = new ArrayList<Produk>(); try { String qry = "SELECT * FROM produk,suplier,jenis,stok_produk WHERE produk.id_jenis = jenis.id_jenis AND produk.id_suplier = suplier.id_suplier AND produk.id_produk=stok_produk.id_produk"; ResultSet rs = stm.executeQuery(qry); while (rs.next()) { Produk p = new Produk(); p.setIdProduk(rs.getInt("id_produk")); p.setNamaProduk(rs.getString("nama_produk")); p.setJenis(rs.getString("nama_jenis")); p.setHarga(rs.getInt("harga")); p.setStok(rs.getInt("stok")); p.setNamaSuplier(rs.getString("nama_suplier")); p.setComboJenis(cbJenis); dataProduk.add(p); } } catch (Exception err) { err.printStackTrace(); } model = new TableModelProduk(dataProduk); tabel.setModel(model); tabel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); class EditProdukListener implements TableModelListener { public void tableChanged(TableModelEvent tme) { int baris = tme.getFirstRow(); int kolom = tme.getColumn(); TableModel model = (TableModel) tme.getSource(); int id = (Integer) model.getValueAt(baris, 0); String query = ""; switch (kolom) { case 1: String nama = (String) model.getValueAt(baris, kolom); query = "UPDATE produk SET nama_produk='" + nama + "' WHERE id_produk=" + id; prosesEdit(query); break; case 2: String jenis = (String) model.getValueAt(baris, kolom); try { query = "select * from jenis where nama_jenis='" + jenis + "'"; ResultSet rs = stm.executeQuery(query); if (rs.next()) { int idJenis = rs.getInt("id_jenis"); query = "UPDATE produk SET id_jenis=" + idJenis + " WHERE id_produk=" + id; prosesEdit(query); } else { setDataTabel(); JOptionPane.showMessageDialog(null, "gagal,jenis tidak ada"); } } catch (SQLException SQLerr) { SQLerr.printStackTrace(); } break; case 3: int stok = (Integer) model.getValueAt(baris, kolom); query = "UPDATE `stok_produk` SET stok=" + stok + " WHERE id_produk=" + id; prosesEdit(query); break; case 4: int harga = (Integer) model.getValueAt(baris, kolom); query = "UPDATE produk SET harga=" + harga + " WHERE id_produk=" + id; prosesEdit(query); break; case 5: String suplier = (String) model.getValueAt(baris, kolom); try { query = "SELECT * FROM suplier WHERE nama_suplier='" + suplier + "'"; ResultSet rs = stm.executeQuery(query); if (rs.next()) { int idSuplier = rs.getInt("id_suplier"); query = "UPDATE produk SET id_suplier=" + idSuplier + " WHERE id_produk=" + id; prosesEdit(query); } else { setDataTabel(); JOptionPane.showMessageDialog(null, "gagal,suplier belum terdaftar"); } } catch (SQLException SQLerr) { SQLerr.printStackTrace(); } break; default: break; } } private void prosesEdit(String query) { try { int hasil = stm.executeUpdate(query); if (hasil == 1) { setDataTabel(); JOptionPane.showMessageDialog(null, "edit berhasil"); } else { JOptionPane.showMessageDialog(null, "gagal"); } } catch (SQLException SQLerr) { SQLerr.printStackTrace(); } } } model.addTableModelListener(new EditProdukListener()); }
public void clear() { table.setModel(model); offset = 0; scrollBar.setValue(0); scrollBar.setMaximum(0); }
/** * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup * memory monitor components, then starts things off. */ public MainFrame() { setupMemoryMonitor(); // Set up the main frame. mainFrame = new JFrame(basicTitle); mainFrame.setJMenuBar(setupMenuBar()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the JTable. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setSelectionBackground(COLOR_SELECTION_BACKGROUND); table.setShowGrid(true); // Add a blank table model so that the component renders properly on // startup. table.setModel(blankDataModel); // Add a list selection listener so we can tell the matchInfoPanel // that a new name was selected. table .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (currentCSV == null) return; int row = table.getSelectedRow(); int column = table.getSelectedColumn(); columnInfoPanel.columnChanged(column); Object o = table.getModel().getValueAt(row, column); if (Name.class.isAssignableFrom(o.getClass())) { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column); } else { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1); } } }); // Set up the left panel (table + matchInfoPanel) JPanel leftPanel = new JPanel(); matchInfoPanel = new MatchInformationPanel(this); leftPanel.setLayout(new BorderLayout()); leftPanel.add(matchInfoPanel, BorderLayout.SOUTH); leftPanel.add(new JScrollPane(table)); // Set up the right panel (columnInfoPanel) JPanel rightPanel = new JPanel(); columnInfoPanel = new ColumnInformationPanel(this); progressBar.setStringPainted(true); rightPanel.setLayout(new BorderLayout()); rightPanel.add(columnInfoPanel); rightPanel.add(progressBar, BorderLayout.SOUTH); // Set up a JSplitPane to split the panels up. JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel); split.setResizeWeight(1); mainFrame.add(split); mainFrame.pack(); // Set up a drop target so we can pick up files mainFrame.setDropTarget( new DropTarget( mainFrame, new DropTargetAdapter() { @Override public void dragEnter(DropTargetDragEvent dtde) { // Accept any drags. dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } @Override public void dragOver(DropTargetDragEvent dtde) {} @Override public void dropActionChanged(DropTargetDragEvent dtde) {} @Override public void dragExit(DropTargetEvent dte) {} @Override public void drop(DropTargetDropEvent dtde) { // Accept a drop as long as its File List. if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = dtde.getTransferable(); try { java.util.List<File> files = (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); // If we're given multiple files, pick up only the last file and load that. File f = files.get(files.size() - 1); loadFile(f, DarwinCSV.FILE_CSV_DELIMITED); } catch (UnsupportedFlavorException ex) { dtde.dropComplete(false); } catch (IOException ex) { dtde.dropComplete(false); } } } })); }
private <T extends Enum<T>> void createControls(JPanel panel, ZrtpConfigureTableModel<T> model) { ResourceManagementService resources = NeomediaActivator.getResources(); final JButton upButton = new JButton(resources.getI18NString("impl.media.configform.UP")); upButton.setOpaque(false); final JButton downButton = new JButton(resources.getI18NString("impl.media.configform.DOWN")); downButton.setOpaque(false); Container buttonBar = new TransparentPanel(new GridLayout(0, 1)); buttonBar.add(upButton); buttonBar.add(downButton); panel.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); panel.setLayout(new GridBagLayout()); final JTable table = new JTable(model.getRowCount(), 2); table.setShowGrid(false); table.setTableHeader(null); table.setModel(model); // table.setFillsViewportHeight(true); // Since 1.6 only - nicer view /* * The first column contains the check boxes which enable/disable their * associated encodings and it doesn't make sense to make it wider than * the check boxes. */ TableColumnModel tableColumnModel = table.getColumnModel(); TableColumn tableColumn = tableColumnModel.getColumn(0); tableColumn.setMaxWidth(tableColumn.getMinWidth() + 5); table.doLayout(); GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.CENTER; constraints.fill = GridBagConstraints.BOTH; constraints.gridwidth = 1; constraints.gridx = 0; constraints.gridy = 1; constraints.weightx = 1; constraints.weighty = 1; panel.add(new JScrollPane(table), constraints); constraints.anchor = GridBagConstraints.NORTHEAST; constraints.fill = GridBagConstraints.NONE; constraints.gridwidth = 1; constraints.gridx = 1; constraints.gridy = 1; constraints.weightx = 0; constraints.weighty = 0; panel.add(buttonBar, constraints); ListSelectionListener tableSelectionListener = new ListSelectionListener() { @SuppressWarnings("unchecked") public void valueChanged(ListSelectionEvent event) { if (table.getSelectedRowCount() == 1) { int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table.getModel(); upButton.setEnabled(selectedRow > 0 && model.checkEnableUp(selectedRow)); downButton.setEnabled( selectedRow < (table.getRowCount() - 1) && model.checkEnableDown(selectedRow)); return; } } upButton.setEnabled(false); downButton.setEnabled(false); } }; table.getSelectionModel().addListSelectionListener(tableSelectionListener); TableModelListener tableListener = new TableModelListener() { @SuppressWarnings("unchecked") public void tableChanged(TableModelEvent e) { if (table.getSelectedRowCount() == 1) { int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table.getModel(); upButton.setEnabled(selectedRow > 0 && model.checkEnableUp(selectedRow)); downButton.setEnabled( selectedRow < (table.getRowCount() - 1) && model.checkEnableDown(selectedRow)); return; } } upButton.setEnabled(false); downButton.setEnabled(false); } }; table.getModel().addTableModelListener(tableListener); tableSelectionListener.valueChanged(null); ActionListener buttonListener = new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent event) { Object source = event.getSource(); boolean up; if (source == upButton) up = true; else if (source == downButton) up = false; else return; int index = ((ZrtpConfigureTableModel<T>) table.getModel()) .move(table.getSelectedRow(), up, up); table.getSelectionModel().setSelectionInterval(index, index); } }; upButton.addActionListener(buttonListener); downButton.addActionListener(buttonListener); }