Hi!
Please, explain me why JTextField: txtFirstName and JTextField: txtLastName are not visible on my JPanel: panfortab?! I can see only JTable: tableDetails.
private void createBaseRight() {
JPanel panfortab = new JPanel();
panfortab.setBounds(330, 150, 650, 795);
panfortab.setVisible(true);
panfortab.setOpaque(true);
panfortab.setBorder(bord);
FilterClass fc = new FilterClass();
fc.setVisible(true);
panfortab.add(fc);
pan.add(panfortab, "Right"); // this is a general panel that includes all components that I've created. Now it has BorderLayout.
}
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.RowFilter;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
public class FilterClass extends JPanel {
TableRowSorter rowSorter;
private DefaultTableModel tableModel;
public FilterClass() {
setLayout(new BorderLayout());
initComponents();
rowSorter=new TableRowSorter();
tableModel = (DefaultTableModel) tableDetails.getModel();
rowSorter.setModel(tableModel);
tableDetails.setRowSorter(rowSorter);
}
private void initComponents() {
tableDetails = new javax.swing.JTable();
txtFirstName = new javax.swing.JTextField();
txtLastName = new javax.swing.JTextField();
tableDetails.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"103", "AAA","BBB","Senior programmer", "Male","09.08.1980"},
{"104", "CCC","DDD","Project manager", "Male","27.03.1979"}
},
new String [] {"Reg.num.",
"Name",
"Surename",
"Profession",
"Sex",
"Date of birth"}
));
// Set column widths
tableDetails.setFillsViewportHeight(true);
tableDetails.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumn col;
int width = 100;
col = tableDetails.getColumnModel().getColumn(3);
col.setPreferredWidth(width);
col = tableDetails.getColumnModel().getColumn(5);
col.setPreferredWidth(width);
jScrollPane1 = new javax.swing.JScrollPane(tableDetails, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
add(jScrollPane1, "North");
txtFirstName.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txFirstNameKeyReleased(evt);
}
});
txtLastName.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txtLastNameKeyReleased(evt);
}
});
}
private void txFirstNameKeyReleased(java.awt.event.KeyEvent evt) {
rowSorter.setRowFilter(RowFilter.regexFilter("(?i)^"+txtFirstName.getText(), 0));
}
private void txtLastNameKeyReleased(java.awt.event.KeyEvent evt) {
rowSorter.setRowFilter(RowFilter.regexFilter("(?i)^" +txtLastName.getText(), 1));
}
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tableDetails;
private javax.swing.JTextField txtFirstName;
private javax.swing.JTextField txtLastName;
}