I want when I click the button "edit, add and update programme", The password field comes up and the button "ok" comes up. The ok button is supposed to call the displaytable() method which will display an editable table for the user to change. how do i get the password to work
JButton passcode = new JButton("Edit, add or update programme");//creates button to display editable table
passcode.setBounds(50,200,95,30);
passcode.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { //here
Char[] password = "123456";
JButton button = new JButton("OK");
JPasswordField pf = new JPasswordField();
button.addActionListener(e1 -> {
if(JPasswordField.getPassword.equals(password){
panel1.add(pf);
panel1.add(button); //TO HERE IM HAVING A PROBLEM WITH
}
});
}
});
A better design would be to add these Components initially but disable them (setEnabled(false)). Anyway, to answer your question in the scenario you have, you should run your code on the UI thread, and revalidate and repaint after adding the new components