List of usage examples for javax.swing JTable getValueAt
public Object getValueAt(int row, int column)
row
and column
. From source file:com.mirth.connect.client.ui.EditMessageDialog.java
private void initSourceMapTable(Map<String, Object> sourceMap) { Object[][] data = new Object[sourceMap.size()][2]; int i = 0;/*w w w . j a va2s .c o m*/ for (Entry<String, Object> entry : sourceMap.entrySet()) { data[i][0] = entry.getKey(); data[i][1] = entry.getValue(); i++; } sourceMapTable = new MirthTable(); sourceMapTable.setModel(new RefreshTableModel(data, new Object[] { "Variable", "Value" }) { @Override public boolean isCellEditable(int row, int column) { return true; } }); sourceMapTable.setDragEnabled(false); sourceMapTable.setRowSelectionAllowed(true); sourceMapTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sourceMapTable.setRowHeight(UIConstants.ROW_HEIGHT); sourceMapTable.setFocusable(false); sourceMapTable.setOpaque(true); sourceMapTable.getTableHeader().setResizingAllowed(false); sourceMapTable.getTableHeader().setReorderingAllowed(false); sourceMapTable.setSortable(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { sourceMapTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } sourceMapTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { deleteButton.setEnabled(sourceMapTable.getSelectedRow() > -1); } } }); class SourceMapTableCellEditor extends AbstractCellEditor implements TableCellEditor { private JTable table; private int column; private JTextField textField; private Object originalValue; private String newValue; public SourceMapTableCellEditor(JTable table, int column) { super(); this.table = table; this.column = column; textField = new JTextField(); textField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { textField.setCaretPosition(textField.getText().length()); } }); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; newValue = null; textField.setText(String.valueOf(value)); return textField; } @Override public Object getCellEditorValue() { if (newValue != null) { return newValue; } else { return originalValue; } } @Override public boolean stopCellEditing() { if (!valueChanged()) { super.cancelCellEditing(); } else { newValue = textField.getText(); } return super.stopCellEditing(); } private boolean valueChanged() { String value = textField.getText(); if (StringUtils.isBlank(value)) { return false; } for (int i = 0; i < table.getRowCount(); i++) { Object tableValue = table.getValueAt(i, column); if (tableValue != null && String.valueOf(tableValue).equals(value)) { return false; } } return true; } } sourceMapTable.getColumnModel().getColumn(0).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 0)); sourceMapTable.getColumnModel().getColumn(1).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 1)); sourceMapScrollPane.setViewportView(sourceMapTable); deleteButton.setEnabled(false); }
From source file:edu.ucla.stat.SOCR.chart.Chart.java
public void updateExample(ChartExampleData example) { // reset();/*from w ww. j a v a 2 s. c o m*/ hasExample = true; JTable tempDataTable = example.getExample(); /* if(tempDataTable.getRowCount()>dataTable.getRowCount()) appendTableRows(tempDataTable.getRowCount()-dataTable.getRowCount()); else */ resetTableRows(tempDataTable.getRowCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } dTableHeader = new EditableHeader(columnModel); dataTable.setTableHeader(dTableHeader); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); JScrollPane tablePanel = new JScrollPane(dataTable); tablePanel.setRowHeaderView(headerTable); dataPanel.add(tablePanel); dataPanel.add(new JScrollPane(summaryPanel)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); //updateStatus("Example updated, please redo the mapping and update the chart"); }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param table// www . j a va 2s . co m * @param model * @return */ public static JTable autoResizeColWidth(final JTable table, final DefaultTableModel model) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setModel(model); int margin = 5; DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); int preferredWidthTotal = 0; int renderedWidthTotal = 0; int[] colWidths = new int[table.getColumnCount()]; for (int i = 0; i < table.getColumnCount(); i++) { int vColIndex = i; TableColumn col = colModel.getColumn(vColIndex); int width = 0; // Get width of column header TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); width = comp.getPreferredSize().width; // Get maximum width of column data for (int r = 0; r < table.getRowCount(); r++) { renderer = table.getCellRenderer(r, vColIndex); comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r, vColIndex); width = Math.max(width, comp.getPreferredSize().width); } // Add margin width += 2 * margin; preferredWidthTotal += col.getPreferredWidth(); colWidths[i] = width; renderedWidthTotal += width; } if (renderedWidthTotal > preferredWidthTotal) { for (int i = 0; i < table.getColumnCount(); i++) { colModel.getColumn(i).setPreferredWidth(colWidths[i]); } } ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.LEFT); // table.setAutoCreateRowSorter(true); table.getTableHeader().setReorderingAllowed(false); return table; }
From source file:com.mirth.connect.connectors.http.HttpListener.java
private void initComponentsManual() { staticResourcesTable.setModel(new RefreshTableModel(StaticResourcesColumn.getNames(), 0) { @Override//from ww w.j a v a 2s . com public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } }); staticResourcesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); staticResourcesTable.setRowHeight(UIConstants.ROW_HEIGHT); staticResourcesTable.setFocusable(true); staticResourcesTable.setSortable(false); staticResourcesTable.setOpaque(true); staticResourcesTable.setDragEnabled(false); staticResourcesTable.getTableHeader().setReorderingAllowed(false); staticResourcesTable.setShowGrid(true, true); staticResourcesTable.setAutoCreateColumnsFromModel(false); staticResourcesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); staticResourcesTable.setRowSelectionAllowed(true); staticResourcesTable.setCustomEditorControls(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { staticResourcesTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } class ContextPathCellEditor extends TextFieldCellEditor { public ContextPathCellEditor() { getTextField().setDocument(new MirthFieldConstraints("^\\S*$")); } @Override protected boolean valueChanged(String value) { if (StringUtils.isEmpty(value) || value.equals("/")) { return false; } if (value.equals(getOriginalValue())) { return false; } for (int i = 0; i < staticResourcesTable.getRowCount(); i++) { if (value.equals(fixContentPath((String) staticResourcesTable.getValueAt(i, StaticResourcesColumn.CONTEXT_PATH.getIndex())))) { return false; } } parent.setSaveEnabled(true); return true; } @Override public Object getCellEditorValue() { String value = fixContentPath((String) super.getCellEditorValue()); String baseContextPath = getBaseContextPath(); if (value.equals(baseContextPath)) { return null; } else { return fixContentPath(StringUtils.removeStartIgnoreCase(value, baseContextPath + "/")); } } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { String resourceContextPath = fixContentPath((String) value); setOriginalValue(resourceContextPath); getTextField().setText(getBaseContextPath() + resourceContextPath); return getTextField(); } } ; staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex()) .setCellEditor(new ContextPathCellEditor()); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex()) .setCellRenderer(new DefaultTableCellRenderer() { @Override protected void setValue(Object value) { super.setValue(getBaseContextPath() + fixContentPath((String) value)); } }); class ResourceTypeCellEditor extends MirthComboBoxTableCellEditor implements ActionListener { private Object originalValue; public ResourceTypeCellEditor(JTable table, Object[] items, int clickCount, boolean focusable) { super(table, items, clickCount, focusable, null); for (ActionListener actionListener : comboBox.getActionListeners()) { comboBox.removeActionListener(actionListener); } comboBox.addActionListener(this); } @Override public boolean stopCellEditing() { if (ObjectUtils.equals(getCellEditorValue(), originalValue)) { cancelCellEditing(); } else { parent.setSaveEnabled(true); } return super.stopCellEditing(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; return super.getTableCellEditorComponent(table, value, isSelected, row, column); } @Override public void actionPerformed(ActionEvent evt) { ((AbstractTableModel) staticResourcesTable.getModel()).fireTableCellUpdated( staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex()); stopCellEditing(); fireEditingStopped(); } } String[] resourceTypes = ResourceType.stringValues(); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMinWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMaxWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .setCellEditor(new ResourceTypeCellEditor(staticResourcesTable, resourceTypes, 1, false)); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .setCellRenderer(new MirthComboBoxTableCellRenderer(resourceTypes)); class ValueCellEditor extends AbstractCellEditor implements TableCellEditor { private JPanel panel; private JLabel label; private JTextField textField; private String text; private String originalValue; public ValueCellEditor() { panel = new JPanel(new MigLayout("insets 0 1 0 0, novisualpadding, hidemode 3")); panel.setBackground(UIConstants.BACKGROUND_COLOR); label = new JLabel(); label.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent evt) { new ValueDialog(); stopCellEditing(); } }); panel.add(label, "grow, pushx, h 19!"); textField = new JTextField(); panel.add(textField, "grow, pushx, h 19!"); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Object getCellEditorValue() { if (label.isVisible()) { return text; } else { return textField.getText(); } } @Override public boolean stopCellEditing() { if (ObjectUtils.equals(getCellEditorValue(), originalValue)) { cancelCellEditing(); } else { parent.setSaveEnabled(true); } return super.stopCellEditing(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { boolean custom = table.getValueAt(row, StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .equals(ResourceType.CUSTOM.toString()); label.setVisible(custom); textField.setVisible(!custom); panel.setBackground(table.getSelectionBackground()); label.setBackground(panel.getBackground()); label.setMaximumSize(new Dimension(table.getColumnModel().getColumn(column).getWidth(), 19)); String text = (String) value; this.text = text; originalValue = text; label.setText(text); textField.setText(text); return panel; } class ValueDialog extends MirthDialog { public ValueDialog() { super(parent, true); setTitle("Custom Value"); setPreferredSize(new Dimension(600, 500)); setLayout(new MigLayout("insets 12, novisualpadding, hidemode 3, fill", "", "[grow]7[]")); setBackground(UIConstants.BACKGROUND_COLOR); getContentPane().setBackground(getBackground()); final MirthSyntaxTextArea textArea = new MirthSyntaxTextArea(); textArea.setSaveEnabled(false); textArea.setText(text); textArea.setBorder(BorderFactory.createEtchedBorder()); add(textArea, "grow"); add(new JSeparator(), "newline, grow"); JPanel buttonPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3")); buttonPanel.setBackground(getBackground()); JButton openFileButton = new JButton("Open File..."); openFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String content = parent.browseForFileString(null); if (content != null) { textArea.setText(content); } } }); buttonPanel.add(openFileButton); JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { text = textArea.getText(); label.setText(text); textField.setText(text); staticResourcesTable.getModel().setValueAt(text, staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex()); parent.setSaveEnabled(true); dispose(); } }); buttonPanel.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { dispose(); } }); buttonPanel.add(cancelButton); add(buttonPanel, "newline, right"); pack(); setLocationRelativeTo(parent); setVisible(true); } } } ; staticResourcesTable.getColumnExt(StaticResourcesColumn.VALUE.getIndex()) .setCellEditor(new ValueCellEditor()); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMinWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMaxWidth(150); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()) .setCellEditor(new TextFieldCellEditor() { @Override protected boolean valueChanged(String value) { if (value.equals(getOriginalValue())) { return false; } parent.setSaveEnabled(true); return true; } }); staticResourcesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (getSelectedRow(staticResourcesTable) != -1) { staticResourcesLastIndex = getSelectedRow(staticResourcesTable); staticResourcesDeleteButton.setEnabled(true); } else { staticResourcesDeleteButton.setEnabled(false); } } }); contextPathField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent evt) { changedUpdate(evt); } @Override public void removeUpdate(DocumentEvent evt) { changedUpdate(evt); } @Override public void changedUpdate(DocumentEvent evt) { ((AbstractTableModel) staticResourcesTable.getModel()).fireTableDataChanged(); } }); staticResourcesDeleteButton.setEnabled(false); }
From source file:interfaces.InterfazPrincipal.java
private void botonBuscarClienteCrearFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonBuscarClienteCrearFacturaActionPerformed String nombre = nombreClienteCrearFactura.getText(); String identificacion = IdentificacionClienteBuscarFactura.getText(); ControladorCliente controladorCliente = new ControladorCliente(); try {//from ww w.j a va 2s . c o m int id = 0; if (!identificacion.equals("")) { id = Integer.parseInt(identificacion); } ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes(nombre, id); if (listaClientes.isEmpty()) { mensajesBusquedaClientesFactura.setText("La busqueda no arrojo resultados"); return; } final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); /*Vector col = new Vector(); col.add("1"); col.add("2"); col.add("3"); col.add("4"); Vector row = new Vector(); for (int i = 0; i < listaClientes.size(); i++) { Cliente cliente = listaClientes.get(i); Vector temp = new Vector(); temp.add((i + 1) + ""); temp.add(cliente.getNombre()); temp.add(cliente.getCliente_id() + ""); temp.add(cliente.getMonto_prestamo() + ""); System.out.println("info" + cliente.getNombre() + "," + cliente.getMonto_prestamo()); row.add(temp); } final JTable table = new JTable(row, col); */ final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Monto Prestamo"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2", "3", "4" }; data[0] = (i + 1); data[1] = listaClientes.get(i).getCliente_id(); data[2] = listaClientes.get(i).getNombre(); data[3] = listaClientes.get(i).getMonto_prestamo(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Monto Prestamo").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); String identificacion = table.getValueAt(table.getSelectedRow(), 3).toString(); ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(identificacion) + " and estado=\"fiado\") order by factura_id"); double pago = 0.0; for (int i = 0; i < flujosCliente.size(); i++) { String[] datos = flujosCliente.get(i); Object[] rowData = { datos[1], datos[2], datos[3], datos[4] }; if (datos[2].equals("deuda")) { pago += Double.parseDouble(datos[4]); } else { pago -= Double.parseDouble(datos[4]); } } nombreClienteCrearFactura.setText(table.getValueAt(table.getSelectedRow(), 2).toString()); IdentificacionClienteBuscarFactura .setText(table.getValueAt(table.getSelectedRow(), 1).toString()); double montoPrestamo = Double .parseDouble(table.getValueAt(table.getSelectedRow(), 3).toString()); Double totalDisponible = montoPrestamo - pago; valorActualPrestamo.setText(String.valueOf(totalDisponible)); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); botonAgregarProducto.setEnabled(true); botonGuardarFactura.setEnabled(true); botonEstablecerMontoFactura.setEnabled(true); dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; //panelDialogo.add(table, c); panelDialogo.add(scroll, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } catch (Exception e) { mensajesBusquedaClientesFactura.setText("La identificacion debe ser un numero"); } }
From source file:interfaces.InterfazPrincipal.java
private void botonAgregarProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarProductoActionPerformed String nombre = jTextField_Factura_Producto_Nombre.getText(); String descripcion = jTextField_Factura_Producto_Descripcion.getText(); ControladorProducto controladorPro = new ControladorProducto(); String restriccion = ""; boolean encounter = true; if (!nombre.equals("")) { if (encounter) { encounter = false;/*from w w w . j av a 2 s. c o m*/ restriccion = " where "; } else { restriccion += " OR "; } restriccion += " nombre like '%" + nombre + "%'"; } if (!descripcion.equals("")) { if (encounter) { encounter = false; restriccion = " where "; } else { restriccion += " OR "; } restriccion += " descripcion like '%" + descripcion + "%'"; } ArrayList<Productos> listaDeProductos = controladorPro.getProducto(restriccion); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 6; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Descripcion"); modeloTabla.addColumn("Unidades Disponibles"); modeloTabla.addColumn("Precio"); //LLenar tabla for (int i = 0; i < listaDeProductos.size(); i++) { Object[] data = { "1", "2", "3", "4", "5", "6" }; data[0] = (i + 1); data[1] = listaDeProductos.get(i).getProductoId(); data[2] = listaDeProductos.get(i).getNombre(); data[3] = listaDeProductos.get(i).getDescripcion(); data[4] = listaDeProductos.get(i).getUnidadesDisponibles(); data[5] = listaDeProductos.get(i).getPrecio(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Descripcion").setMinWidth(110); table.getColumn("Unidades Disponibles").setMinWidth(40); table.getColumn("Precio").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); //final JTable table = new JTable(row, col); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); DefaultTableModel modelo = (DefaultTableModel) TablaDeFacturaProducto.getModel(); Object[] fila = new Object[7]; fila[0] = table.getValueAt(table.getSelectedRow(), 0).toString(); fila[1] = table.getValueAt(table.getSelectedRow(), 1).toString(); fila[2] = table.getValueAt(table.getSelectedRow(), 2).toString(); fila[3] = table.getValueAt(table.getSelectedRow(), 3).toString(); //fila[4] = table.getValueAt(table.getSelectedRow(), 4).toString(); fila[4] = (String) JOptionPane.showInputDialog("Ingrese el nmero de unidades que va a vender"); fila[5] = table.getValueAt(table.getSelectedRow(), 5).toString(); Double valorProducto = Double.parseDouble((String) fila[5]); String valorActualProducto = String.valueOf(Double.parseDouble(valorActualFactura.getText()) + Double.parseDouble((String) fila[4]) * valorProducto); valorActualFactura.setText(valorActualProducto); fila[6] = Double.parseDouble((String) fila[4]) * valorProducto; modelo.addRow(fila); //modelo.getColumnName(4). /*TablaDeFacturaProducto.setModel(modelo); TablaDeFacturaProducto.getColumnClass(4). ;*/ dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; panelDialogo.add(scroll, c); //panelDialogo.add(table, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void BotonBuscarClienteSaldoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBuscarClienteSaldoActionPerformed String nombreCliente = nombreClienteBusquedaSaldo.getText(); //08-11-2014 listar clientes por nombre ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = new ArrayList<>(); if (nombreCliente.equals("")) { listaClientes = controladorCliente.obtenerClientes(); } else {/*ww w . ja v a 2 s . c o m*/ listaClientes = controladorCliente.obtenerClientes(nombreCliente, 0); } //08-11-2014 Crear dialogo de bsqueda final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(300, 300); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2" }; data[0] = listaClientes.get(i).getCliente_id(); data[1] = listaClientes.get(i).getNombre(); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Identificacin").setMinWidth(110); tablaDialogo.getColumn("Nombre").setMinWidth(110); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); mostrarIdentificacionCliente.setText(String.valueOf(identificacionCliente)); String nombreClientePago = String.valueOf(tablaDialogo.getValueAt(row, 1)); //Limitar a 15 caracteres if (nombreClientePago.length() >= 15) { nombreClientePago = nombreClientePago.substring(0, 12); } textoPersonaSaldo.setText(nombreClientePago); DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoClientes.getModel(); for (int i = 0; i < modeloClientes.getRowCount(); i++) { modeloClientes.removeRow(i); } modeloClientes.setRowCount(0); ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(identificacionCliente) + " and estado=\"fiado\") order by factura_id"); double pago = 0.0; for (int i = 0; i < flujosCliente.size(); i++) { String[] datos = flujosCliente.get(i); TablaDeSaldoClientes.setModel(modeloClientes); NumberFormat formatter = new DecimalFormat("#0"); String valorMovimiento = String.valueOf(formatter.format(Double.parseDouble(datos[4]))); Object[] rowData = { datos[1], datos[2], datos[3], valorMovimiento }; if (datos[2].equals("deuda")) { pago += Double.parseDouble(datos[4]); } else { pago -= Double.parseDouble(datos[4]); } modeloClientes.addRow(rowData); } TablaDeSaldoClientes.setModel(modeloClientes); NumberFormat formatter = new DecimalFormat("#0"); textoTotalDebe.setText(String.valueOf(formatter.format(pago))); dialogoEditar.dispose(); //Mostrar en table de clientes los datos botonRegistrarAbono.setEnabled(true); } } }); }
From source file:interfaces.InterfazPrincipal.java
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed String nombreCliente = nombreClienteReporteCliente.getText(); String identificacion = identificacionClienteCliente.getText(); try {//from www . j a v a 2 s .c o m //08-11-2014 listar clientes por nombre ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = new ArrayList<Cliente>(); if (nombreCliente.equals("") && identificacion.equals("")) { listaClientes = controladorCliente.obtenerClientes(); } else { int identificacionNumerico = 0; if (!identificacion.equals("")) { identificacionNumerico = Integer.parseInt(identificacion); } listaClientes = controladorCliente.obtenerClientes(nombreCliente, identificacionNumerico); } //08-11-2014 Crear dialogo de bsqueda final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(300, 300); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2" }; data[0] = listaClientes.get(i).getCliente_id(); data[1] = listaClientes.get(i).getNombre(); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Identificacin").setMinWidth(110); tablaDialogo.getColumn("Nombre").setMinWidth(110); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); jTextFieldIdentificacionClienteReporte.setText(String.valueOf(identificacionCliente)); botonGenerarReporteCliente.setEnabled(true); dialogoEditar.dispose(); } } }); // TODO add your handling code here: } catch (Exception e) { JOptionPane.showMessageDialog(this, "El valor de la identificacin de ser numrico"); } }
From source file:interfaces.InterfazPrincipal.java
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed // TODO add your handling code here: String nombre = jTextFieldNombreSaldoProveedores.getText(); ControladorProveedores controladorProveedores = new ControladorProveedores(); ArrayList<Proveedores> listaProveedores = controladorProveedores.obtenerProveedores("", nombre); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar proveedores"); dialogoEditar.setSize(500, 300);/*from www . ja va 2 s .c o m*/ dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar Proveedores"); c.gridx = 0; c.gridy = 0; c.gridwidth = 3; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 3; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("ID"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaProveedores.size(); i++) { Object[] data = { "1", "2", "3" }; data[0] = listaProveedores.get(i).getID(); data[1] = listaProveedores.get(i).getIdentificacion(); data[2] = listaProveedores.get(i).getNombre(); System.out.println("Nombre!!" + data[2]); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("ID").setMinWidth(70); tablaDialogo.getColumn("Identificacin").setMinWidth(60); tablaDialogo.getColumn("Nombre").setMinWidth(150); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); Object idCliente = tablaDialogo.getValueAt(row, 1); mostrarIDProveedor.setText(String.valueOf(identificacionCliente)); String nombreClientePago = String.valueOf(tablaDialogo.getValueAt(row, 2)); //Limitar a 15 caracteres if (nombreClientePago.length() >= 15) { nombreClientePago = nombreClientePago.substring(0, 12); } textoNombreProveedor.setText(nombreClientePago); DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoProveedor.getModel(); for (int i = 0; i < modeloClientes.getRowCount(); i++) { modeloClientes.removeRow(i); } modeloClientes.setRowCount(0); ControladorFlujoCompras controladorFlujoCompra = new ControladorFlujoCompras(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<Flujo_Compra> flujosProveedor = controladorFlujoCompra.obtenerFlujosCompras( " where ID_CompraProveedor in (select ID_CompraProveedor from Compra_Proveedores where IDProveedor = " + String.valueOf(identificacionCliente) + ") order by ID_CompraProveedor"); double pago = 0.0; for (int i = 0; i < flujosProveedor.size(); i++) { Flujo_Compra datos = flujosProveedor.get(i); Object[] rowData = { datos.getID_CompraProveedor(), datos.getTipo_flujo(), datos.getFecha(), datos.getMonto() }; if (datos.getTipo_flujo().equals("deuda")) { pago += Double.parseDouble(datos.getMonto() + ""); } else { pago -= Double.parseDouble(datos.getMonto() + ""); } modeloClientes.addRow(rowData); } TablaDeSaldoProveedor.setModel(modeloClientes); deudaActualProveedor.setText(String.valueOf(pago)); dialogoEditar.dispose(); //Mostrar en table de clientes los datos botonRegistrarAbono.setEnabled(true); } } }); }
From source file:net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.GenericWikiTableTransformer.java
/** * @see/*from w w w. j a va 2 s.com*/ * net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableTransformer * #transform(javax.swing.JTable) */ @Override public String transform(JTable table) { int nbrSelRows = table.getSelectedRowCount(); int nbrSelCols = table.getSelectedColumnCount(); int[] selRows = table.getSelectedRows(); int[] selCols = table.getSelectedColumns(); if (selRows.length != 0 && selCols.length != 0) { StringBuilder buf = new StringBuilder(1024); // Start the table appendWithReplacement(buf, configuration.getTableStartTag()); // Create the header appendWithReplacement(buf, configuration.getHeaderStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { appendWithReplacement(buf, configuration.getHeaderCell(), table.getColumnName(selCols[colIdx])); } appendWithReplacement(buf, configuration.getHeaderEndTag()); // Now fill all the table rows for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx) { appendWithReplacement(buf, configuration.getRowStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { TableCellRenderer cellRenderer = table.getCellRenderer(selRows[rowIdx], selCols[colIdx]); Object cellObj = table.getValueAt(selRows[rowIdx], selCols[colIdx]); if (cellRenderer instanceof SquirrelTableCellRenderer) { cellObj = ((SquirrelTableCellRenderer) cellRenderer).renderValue(cellObj); } String value = null; if (cellObj == null) { value = ""; //$NON-NLS-1$ } else { final String tmp = cellObj.toString(); if (tmp.trim().equals("")) { //$NON-NLS-1$ value = ""; //$NON-NLS-1$ } else { value = tmp; } } appendWithReplacement(buf, configuration.getDataCell(), value); } appendWithReplacement(buf, configuration.getRowEndTag()); } appendWithReplacement(buf, configuration.getTableEndTag()); return buf.toString(); } else { return null; } }