Java JTable Column buscarDescripcion(KeyEvent e, JTable pTabla, JTextField pTextoDeBusqueda, int pColumna)

Here you can find the source of buscarDescripcion(KeyEvent e, JTable pTabla, JTextField pTextoDeBusqueda, int pColumna)

Description

buscar Descripcion

License

Open Source License

Declaration

public static boolean buscarDescripcion(KeyEvent e, JTable pTabla,
            JTextField pTextoDeBusqueda, int pColumna) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;

public class Main {
    public static boolean buscarDescripcion(KeyEvent e, JTable pTabla,
            JTextField pTextoDeBusqueda, int pColumna) {
        boolean findRecord = false;
        if ((e.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
                && (e.getKeyCode() != KeyEvent.VK_ENTER)) {
            String vFindText = pTextoDeBusqueda.getText().toUpperCase();
            String vDescrip = "";
            for (int k = 0; k < pTabla.getRowCount(); k++) {
                vDescrip = ((String) pTabla.getValueAt(k, pColumna))
                        .toUpperCase().trim();
                if (vDescrip.length() >= vFindText.length()) {
                    vDescrip = vDescrip.substring(0, vFindText.length());
                    if (vFindText.equalsIgnoreCase(vDescrip)) {
                        showCell(pTabla, k, 0);
                        findRecord = true;
                        break;
                    }// w  ww.  ja va2 s  . com
                }
            }
        }
        return findRecord;
    }

    public static void showCell(JTable table, int row, int column) {
        if (row >= table.getRowCount())
            row = table.getRowCount() - 1;
        Rectangle rect = table.getCellRect(row, column, true);
        table.scrollRectToVisible(rect);
        table.clearSelection();
        table.setRowSelectionInterval(row, row);
    }
}

Related

  1. aceptarTeclaPresionada(KeyEvent e, JTable pTabla, JTextField pTextoDeBusqueda, int pColumna)
  2. addSpaceSelection(final JTable table, final int column)
  3. ajustarAnchoColumnas(JTable table)
  4. cloneTableColumn(TableColumn c)
  5. cloneTableColumnModel(TableColumnModel m)
  6. columnAt(final JTable table, final Point p, final Class columnClazz)
  7. convertColumnIndexToModel(TableColumnModel cm, int viewColumnIndex)