Buenas xd a toda la comunidad,queria ver si me podian ayudar,a ordenar estos 2 archivos,bueno!tengo un JTable conectado a la base de datos,,tengo un JTextField y tengo un JButton,lo que intento hacer es filtrar texto desde un JTextField....
en este primer archivo me corre una jtable con unos datos por default,escribo en el jtextfield y le doy buscar y me encuentra lo que anote en el jtextfield con sorter.setRowFilter ( RowFilter.regexFilter ( text )) ;,pero el PROBLEMA es que sto no esta coenctada a la base de datos y se me vino a la mente que esta funcion la puedo ocupar para buscar datos en un jtable donde si tengo implementado la conexion desde una base de datos,si alguien me pudiera ayudar a implementarlo este es el archivo donde filtra el texto:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
public class RegexTable {
public static void main
( String args
[]) { frame.
setDefaultCloseOperation ( JFrame.
EXIT_ON_CLOSE ) ; Object rows
[][] = { { "A" ,
"About" ,
44.36 } ,
{ "B" ,
"Boy" ,
44.84 } ,
{ "C" ,
"Cat" ,
463.63 } ,
{ "D" , "Day" , 27.14 } , { "E" , "Eat" , 44.57 } , { "F" , "Fail" , 23.15 } ,
{ "G" , "Good" , 4.40 } , { "H" , "Hot" , 24.96 } , { "I" , "Ivey" , 5.45 } ,
{ "J" , "Jack" , 49.54 } , { "K" , "Kids" , 280.00 } } ;
String columns
[] = { "NOMBRE" ,
"DESCRIPCION" ,
"PRECIO" } ; public Class getColumnClass ( int column ) {
Class returnValue;
if (( column >= 0 ) && ( column < getColumnCount ())) {
returnValue = getValueAt ( 0 , column ) .getClass () ;
}
else {
}
return returnValue;
}
} ;
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel> ( model ) ;
table.setRowSorter ( sorter ) ;
button.setBounds(500,100,150,20);
button.addActionListener (
String text
= filterText.
getText () ; if ( text.length () == 0 ) {
sorter.setRowFilter ( null ) ;
}
else {
sorter.setRowFilter ( RowFilter.regexFilter ( text )) ;
}
}
}) ;
frame.setSize ( 300 , 250 ) ;
frame.setVisible ( true ) ;
}
}
y ese es mi archivo donde tengo conectada la base de datos y aqui le quiero implementar un JButton y un JTextField,con los metodos de archivo anterior,pero como NO se como armar los 2 archivos en uno solo me falta algo de logica algoritmica o matematica,pero si alguien me pudiera decir los pasos que debo hacer se lo agradecere bastante
import java.awt.Event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.sql.*;
public static void main
(String[] args
) {
NuevaVentana v=new NuevaVentana();
v.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); v.setVisible(true);
}
}
class NuevaVentana
extends JFrame{ private static final int ancho=300;
private static final int largo=300;
public NuevaVentana(){
this.setTitle("Prueba Tabla");
this.setSize(ancho,largo);
NuevoPanel p=new NuevoPanel();
add(p);
//JButton bt= new JButton("buscar");
//bt.setBounds(300,100,150,20);
// p.add(bt);
}
}
class NuevoPanel
extends JPanel{ {
modelo.addColumn("clave");
modelo.addColumn("Nombre");
modelo.addColumn("descripcion");
}
public NuevoPanel(){
mostrarTabla();
//add ( p, BorderLayout.NORTH ) ;
//bt.setBounds(300,100,150,20);
//add(bt);
bt.addActionListener (
String text
= filterText.
getText () ; if ( text.length () == 0 ) {
sorter.setRowFilter ( null ) ;
}
else {
sorter.setRowFilter ( RowFilter.regexFilter ( text )) ;
}
}
}) ;
}
public void mostrarTabla(){
try
{
ResultSet rs
= s.
executeQuery ("select * from categoria"); while (rs.next())
{
fila[0]=rs.getInt ("clave");
fila[1]=rs.getString ("Nombre");
fila[2]=rs.getString("descripcion");
modelo.addRow(fila);
}
conexion.close();
}
{
e.printStackTrace();
}
}
}
ojala que alguien me pueda ayudar,ya me tarde algo en implementarlo...
NOTA: todo por la che logicaaaa que me faltaa desarrollar,pero bueno!saludos!se los agradecere bastante SI ALGUIEN me ayuda bueno bye!