List of usage examples for javax.swing.event TableModelEvent TableModelEvent
public TableModelEvent(TableModel source, int firstRow, int lastRow, int column, int type)
From source file:ExpenseReport.java
public ExpenseReport() { super("Expense Report"); setSize(570, 200);/*from w ww . ja va 2 s .c o m*/ m_data = new ExpenseReportData(this); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int k = 0; k < ExpenseReportData.m_columns.length; k++) { TableCellRenderer renderer; if (k == ExpenseReportData.COL_APPROVED) renderer = new CheckCellRenderer(); else { DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment); renderer = textRenderer; } TableCellEditor editor; if (k == ExpenseReportData.COL_CATEGORY) editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES)); else if (k == ExpenseReportData.COL_APPROVED) editor = new DefaultCellEditor(new JCheckBox()); else editor = new DefaultCellEditor(new JTextField()); TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.setSize(550, 150); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); ImageIcon penny = new ImageIcon("penny.gif"); m_title = new JLabel("Total: $", penny, JButton.LEFT); m_title.setForeground(Color.black); m_title.setAlignmentY(0.5f); p.add(m_title); p.add(Box.createHorizontalGlue()); JButton bt = new JButton("Insert before"); bt.setMnemonic('b'); bt.setAlignmentY(0.5f); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row); m_table.tableChanged( new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Insert after"); bt.setMnemonic('a'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row + 1); m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Delete row"); bt.setMnemonic('d'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); if (m_data.delete(row)) { m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); calcTotal(); } } }; bt.addActionListener(lst); p.add(bt); getContentPane().add(p, BorderLayout.SOUTH); calcTotal(); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:net.sourceforge.happybank.main.BankMain.java
/** * loads the customer account data/* www. j a v a 2 s . c o m*/ * * @return success (positive) or failure (negative) */ protected int loadAccounts() { try { List<Customer> customers = bank.getCustomers(); Iterator<Customer> custIter = customers.iterator(); Customer cust = null; while (custIter.hasNext()) { cust = custIter.next(); String cid = cust.getId(); Customer customer = bank.getCustomer(cid); List<Account> accounts = bank.getAccounts(cid); Iterator<Account> accIter = accounts.iterator(); Account acc = null; while (accIter.hasNext()) { acc = accIter.next(); String aid = acc.getId(); acc = bank.getAccount(aid); int row = accountEntries.getSelectedRow(); if (acc == null) break; accountModel.insert(new AccountData(aid, acc.getType(), acc.getBalance(), cust.getFirstName(), cust.getLastName(), cid), row + 1); } } // refresh table accountEntries.tableChanged(new TableModelEvent(accountModel, 0, accountModel.getRowCount(), TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); accountEntries.repaint(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Error reading account data", "Read Error", JOptionPane.ERROR_MESSAGE); return -1; } return 0; }
From source file:blue.components.lines.Line.java
public void fireTableRowsInserted(int firstRow, int lastRow) { fireTableChanged(/*from ww w .j a v a 2s. c om*/ new TableModelEvent(this, firstRow, lastRow, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); }
From source file:blue.components.lines.Line.java
public void fireTableRowsUpdated(int firstRow, int lastRow) { fireTableChanged(//from www.jav a 2 s . c o m new TableModelEvent(this, firstRow, lastRow, TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); }
From source file:blue.components.lines.Line.java
public void fireTableRowsDeleted(int firstRow, int lastRow) { fireTableChanged(// w w w.j av a 2s . c o m new TableModelEvent(this, firstRow, lastRow, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); }
From source file:org.jdal.swing.ListTableModel.java
/** * Add a Object to underlaying list//from ww w . j ava 2s .co m * @param o the object to add * @return true if added */ public boolean add(Object o) { boolean result = list.add(o); if (usingChecks) checks.add(Boolean.FALSE); if (list.size() == 1) { // adding on empty list, need to init init(); } fireTableChanged(new TableModelEvent(this, list.size() - 1, list.size() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); return result; }
From source file:org.jdal.swing.ListTableModel.java
/** * Remove a object from underlaying list model * @param index column to remove/* w ww . ja va2 s . com*/ * @return the removed object */ public Object remove(int index) { Object result = list.remove(index); fireTableChanged( new TableModelEvent(this, index, index, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); return result; }
From source file:phex.gui.models.SearchListTableModel.java
/** * Called if a search changed.//from w w w .java 2s.c o m */ public void searchChanged(int position) { lazyEventQueue.addTableModelEvent( new TableModelEvent(this, position, position, TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); }
From source file:phex.gui.models.SearchListTableModel.java
/** * Called if a search was added.// w w w . j av a2 s . co m */ public void searchAdded(int position) { fireTableChanged( new TableModelEvent(this, position, position, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); }
From source file:phex.gui.models.SearchListTableModel.java
/** * Called if a search was removed./*from w w w . j av a 2s . c o m*/ */ public void searchRemoved(int position) { fireTableChanged( new TableModelEvent(this, position, position, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); }