I have a table and in a Jpanel on it I created a textFields and combobox with the intention of using them as a filter. The method:
tableRowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + busca));
Does he expect a string as a filter? If the filter has more than one parameter how do I use it?
My screen looks like this:
ItwouldbesomethinglikeExample:
publicclassteste2extendsjavax.swing.JFrame{//Variaveisprivatejavax.swing.JButtonbtnAplicar;privatejavax.swing.JButtonbtnLimpar;privatejavax.swing.JComboBoxcomboboxCategoria;privatejavax.swing.JComboBoxcomboboxStatus;privatejavax.swing.JScrollPanejScrollPane2;privatejavax.swing.JLabellblAbertura;privatejavax.swing.JLabellblCategoria;privatejavax.swing.JLabellblCliente;privatejavax.swing.JLabellblNumero;privatejavax.swing.JLabellblResponsavel;privatejavax.swing.JLabellblStatus;privatejavax.swing.JLabellblUsuario;privatejavax.swing.JTabletableServicosAbertos;privatejavax.swing.JFormattedTextFieldtxtAbertura;privatejavax.swing.JTextFieldtxtCliente;privatejavax.swing.JFormattedTextFieldtxtNumero;privatejavax.swing.JTextFieldtxtResponsavel;privatejavax.swing.JTextFieldtxtUsuario;publicteste2(){iniciarComponentes();}privatevoidiniciarComponentes(){jScrollPane2=newjavax.swing.JScrollPane();tableServicosAbertos=newjavax.swing.JTable();comboboxStatus=newjavax.swing.JComboBox();lblCategoria=newjavax.swing.JLabel();lblStatus=newjavax.swing.JLabel();txtAbertura=newjavax.swing.JFormattedTextField();lblAbertura=newjavax.swing.JLabel();lblUsuario=newjavax.swing.JLabel();lblResponsavel=newjavax.swing.JLabel();txtUsuario=newjavax.swing.JTextField();txtResponsavel=newjavax.swing.JTextField();lblCliente=newjavax.swing.JLabel();txtCliente=newjavax.swing.JTextField();txtNumero=newjavax.swing.JFormattedTextField();lblNumero=newjavax.swing.JLabel();comboboxCategoria=newjavax.swing.JComboBox();btnAplicar=newjavax.swing.JButton();btnLimpar=newjavax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);setTitle("SiGS - Sistema de gerenciamento de serviços");
setMinimumSize(new java.awt.Dimension(1366, 768));
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
}
});
tableServicosAbertos.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{"OS20160214", "SAS", "Redes", "20/11/2016", "Max Vargas", "Max Vargas", "Aberto"},
{"OS20160242", "Multiserv", "Computadores", "15/07/2016", "Max Vargas", "Mateus Nascimento", "Fechado"},
{"OS20165851", "Telecom", "CFTV", "16/07/2016", "Max Vargas", "Fabio Oliv.", "Fechado"},
{null, null, null, null, null, null, null}
},
new String[]{
"Numero", "Cliente", "Categoria", "Abertura", "Usuario", "Responável", "Status"
}
));
jScrollPane2.setViewportView(tableServicosAbertos);
comboboxStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[]{" ", "Aberto", "Fechado", "Cancelado", "Pausado"}));
lblCategoria.setText("Categoria:");
lblStatus.setText("Status:");
lblAbertura.setText(" Abertura:");
lblUsuario.setText("Usuário:");
lblResponsavel.setText("Responsável:");
lblCliente.setText("Cliente:");
lblNumero.setText("Número:");
comboboxCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[]{" ", "Computadores", "CFTV", "Redes", "Telefonia", "Outros"}));
btnAplicar.setText("OK");
btnLimpar.setText("Limpar");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(lblStatus)
.addGap(15, 15, 15)
.addComponent(comboboxStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(85, 85, 85)
.addComponent(lblResponsavel)
.addGap(5, 5, 5)
.addComponent(txtResponsavel, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblCategoria)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(comboboxCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(104, 104, 104)
.addComponent(lblUsuario)
.addGap(10, 10, 10)
.addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lblAbertura)
.addGap(10, 10, 10)
.addComponent(txtAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(105, 105, 105)
.addComponent(lblCliente)
.addGap(13, 13, 13)
.addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnAplicar, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnLimpar))
.addGroup(layout.createSequentialGroup()
.addComponent(lblNumero)
.addGap(19, 19, 19)
.addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGap(78, 78, 78))
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(90, 90, 90)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCategoria)
.addComponent(comboboxCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(lblUsuario)
.addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblNumero)
.addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblStatus)
.addComponent(comboboxStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblResponsavel)
.addComponent(txtResponsavel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblAbertura)
.addComponent(txtAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblCliente)
.addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(46, 46, 46)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAplicar)
.addComponent(btnLimpar))))
.addContainerGap(241, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}