4
What I’m doing is a little longer, so I’m going to shorten the problem with a more objective example:
I have a registration form and created a modal Jdialog with the fields I want to search. When I search Jdialog I would like to filter the information in the table that is in Jframe. The problem is that it is not working.
Follow code (in this case the example is with the setvisible that tb is not working, I believe it is the same problem):
VISAO (Search screen):
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
FrmCadUsuarios frm = new FrmCadUsuarios();
frm.tbVisivel(true);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
FrmCadUsuarios frm = new FrmCadUsuarios();
frm.tbVisivel(false);
}
VISAO (registration form):
public class FrmCadUsuarios extends javax.swing.JFrame {
private JTable tbUsuarios;
DefaultTableModel modelo = new DefaultTableModel();
public FrmCadUsuarios() {
initComponents();
this.setLocation(550,250);
criaTabela();
jScrollPane1.setViewportView(tbUsuarios);
}
public void tbVisivel (boolean aa) {
tbUsuarios.setVisible(aa);
}
}
I call to JDialog
thus:
private void tb_btn_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {
frmPesquisa pesq = new frmPesquisa(this,false);
pesq.setVisible(true);
}
and try to update a JLabel
on the screen of main
thus has 2 buttons, 1 should make the label visible and the other invisible:
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
FrmCadUsuarios frm = new FrmCadUsuarios();
frm.tbVisivel(this, true);
}
private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
FrmCadUsuarios frm = new FrmCadUsuarios();
frm.tbVisivel(this, false);
}
The Search Form Builder (JDialog
) is as follows:
public frmPesquisa(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setLocation(1300,100);
}
To make filters in
JTable
you need to use the classTableRowSorter
passing hisTableModel
. Add your table model to the question to make it easy to answer.– user28595
Hi Diego! The problem is a little before you get into it. I’m not able to implement Listener, for example, if I create a Jdialog with a textbox and a boot ok, I wanted to update the main form with the contents of this one, but it won’t. I’ve tried everything. I’ve seen examples of how it would work if I did the form only in code, but I’m using the Netbeans interface and it’s not coming off. If you can have a simple example of how it would work it would be great. Thank you :)
– kirito
Oh yes, add to the question how you call the jdialog in the jframe, and how you return the search to it back. With this information (beyond what you already have) can help you.
– user28595
No problem! I call Dialog like this: private void tb_btn_searchActionPerformed(java.awt.Event.Actionevent evt) ' frmPesquisa pesq = new frmPesquisa(this,false); pesq.setVisible(true); }
– kirito
and I try to update a Label on the main screen so it has 2 buttons, 1 should make the label visible and the other invisible: private void btn2ActionPerformed(java.awt.Event.Actionevent evt) ' Frmcadusuarios frm = new Frmcadusuarios(); frm.tbVisivel(this, true); }
– kirito
private void btn3ActionPerformed(java.awt.Event.Actionevent evt) ː Frmcadusuarios frm = new Frmcadusuarios(); frm.tbVisivel(this, false); }
– kirito
The Search form constructor (Jdialog) is as follows: public frmPesquisa(java.awt.Frame Parent, Boolean modal) { super(Parent, modal); initComponents(); this.setLocation(1300,100); }
– kirito