1
I’m having some problems updating the JDialog
created through the WindowsBuilder
no Eclipse (would not be on account of this).
Basically I have a screen Change Registrations of my financial mini-system, I load the information on the logged in user screen and display the others in a JComboBox
.
I created a ActionListener
so that when the JComboBox
is modified, it validates if the selected user is different from what is currently showing. If it is, it loads the new information.
Below an excerpt of code trying to explain:
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.util.ArrayList;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import br.com.base_classes_paper.cadastroBase;
import br.com.classes_paper.cadastroActions;
public class altCadastroUsuario1 extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTextField txtLogin;
private JTextField passSenha;
public cadastroBase valCadBas;
public ArrayList<cadastroBase> cadTotal;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
altCadastroUsuario1 dialog = new altCadastroUsuario1();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public altCadastroUsuario1() {
setTitle("PaperSys");
setBounds(100, 100, 800, 600);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
txtLogin = new JTextField();
txtLogin.setBounds(106, 165, 260, 20);
txtLogin.setText(valCadBas.getLogin());
contentPanel.add(txtLogin);
txtLogin.setColumns(10);
passSenha = new JTextField();
passSenha.setBounds(468, 165, 270, 20);
passSenha.setText(valCadBas.getPass());
contentPanel.add(passSenha);
passSenha.setColumns(10);
JComboBox jComBox_NomeUsuar = new JComboBox();
for (cadastroBase load : cadTotal){
jComBox_NomeUsuar.addItem(load.login);
}
jComBox_NomeUsuar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String selected = (String) jComBox_NomeUsuar.getSelectedItem();
if (selected.equalsIgnoreCase(txtLogin.getText())){
for (cadastroBase load : cadTotal){
if (selected.equalsIgnoreCase(load.nomes)){
valCadBas.setLogin(load.login);
valCadBas.setPass(load.pass);
recarregarTela();
}
}
}
}
});
jComBox_NomeUsuar.setBounds(539, 282, 199, 20);
contentPanel.add(jComBox_NomeUsuar);
}
protected void recarregarTela() {
//altCadastroUsuario.this.removeAll();
altCadastroUsuario1.this.repaint();
altCadastroUsuario1.this.revalidate();
//contentPanel.repaint();
//contentPanel.revalidate();
}
}
In this case, my method would do more or less what is up there, but with some extra fields and internal methods that run in other classes. But the way it is, it doesn’t work.
To see if I can communicate better: I have the screen (generated by the eclipse Windows) that initially displays the data of the user who logged on to the system (let’s assume login and password) via get/set and the other information of all users that it has access to saved in an array by only loading the logins in jcombobox, then when it modifies some house in the combobox I validate if what it changes in jcombobox is different than the one shown on the screen, if yes I load this user information in get/set and try to give refresh of the page by the methods revalidate()
and repaint()
by which they do not update the register (the compiler java running both but nothing happens next). In case you need the whole code I have it tomorrow because today I am not at home.
Hi Giovan, welcome to Stack Overflow. In order for us to help you we need a bigger context about what’s happening and what’s not working. Create a mvce and we started working from there.
– Anthony Accioly
This code does not run, with syntax error. Try to test the code posted before creating the question.
– Bruno César