private void selectCliente() { int selected = table.getSelectedRow(); Persona persona = tableModel.getData().get(selected); controller.getView().getTxtIdCliente().setText(persona.getId().toString()); field.setText(""); buscar(); popup.hidePopup(); controller.cargarCliente(); controller.getView().getTxtIdCliente().requestFocus(); }
public void install() { // Button that calls for popup WebButton showPopup = controller.getView().getBtnBuscarCliente(); // Popup itself popup = new WebButtonPopup(showPopup, PopupWay.downLeft); // Popup content WebLabel label = new WebLabel("Buscador de clientes", WebLabel.CENTER); field = new WebTextField("", 10); table = new WebTable(); tableModel = new ClienteTableModel(); table.setModel(tableModel); table.getColumnModel().getColumn(0).setMaxWidth(40); // Ancho del ID table.getColumnModel().getColumn(1).setMinWidth(280); // Ancho de la razón social table.getColumnModel().getColumn(2).setMinWidth(120); // Ancho del RFC table.getColumnModel().getColumn(3).setMinWidth(120); // Ancho de la calle table.getColumnModel().getColumn(4).setMinWidth(120); // Ancho del colonia table.getColumnModel().getColumn(5).setMinWidth(120); // Ancho del municipio field.setHorizontalAlignment(SwingConstants.CENTER); GroupPanel content = new GroupPanel(5, false, label, field, table); content.setMinimumWidth(800); content.setMargin(15); // Setup events table .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table .getActionMap() .put( "Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { selectCliente(); } }); content .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Escape"); content .getActionMap() .put( "Escape", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { popup.hidePopup(); } }); field.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) selectCliente(); else if (e.getKeyCode() == KeyEvent.VK_DOWN) { int sigFila = table.getSelectedRow() + 1; if (sigFila < table.getRowCount()) { table.setRowSelectionInterval(sigFila, sigFila); table.scrollRectToVisible(table.getCellRect(sigFila, 1, true)); } } else if (e.getKeyCode() == KeyEvent.VK_UP) { int antFila = table.getSelectedRow() - 1; if (antFila >= 0) { table.setRowSelectionInterval(antFila, antFila); table.scrollRectToVisible(table.getCellRect(antFila, 1, true)); } } else preBuscar(); } }); // Setup popup content popup.setContent(content); // Component focused by default popup.setDefaultFocusComponent(field); }