0

Here is my code to create new user. If I try to create new user without logging in it will show a message please log in first. Then I will log in and attempt to create new user. My problem here is the previous text area displayed is still enabled. I'm not able to enter data into my text boxes. I tried using remove() function but no use.

if(e.getSource()==createButton){
    //adminCard.remove(previlege);
    if(UID==0||users.size()==0){
        JPanel newUserCard = new JPanel(new FlowLayout());

        name = new JPanel( new GridLayout(1, 4));
        name.add(new JLabel("              "));
        userName=new JTextField(20);
        name.add(userName);
        name.add(new JLabel(" Name"));

        pword = new JPanel( new GridLayout(1, 4));
        pword.add(new JLabel("               "));
        pwd=new JTextField(20);
        pword.add(pwd);
        pword.add(new JLabel(" Password"));

        loginNamePanel = new JPanel( new GridLayout(1, 4));
        loginNamePanel.add(new JLabel("               "));
        loginName=new JTextField(20);
        loginNamePanel.add(loginName);
        loginNamePanel.add(new JLabel("UserName"));

        JPanel confirmpwd = new JPanel( new GridLayout(1, 3));
        confirmpwd.add(new JLabel("              "));
        confirmPassword=new JTextField(20);
        confirmpwd.add(confirmPassword);
        confirmpwd.add(new JLabel(" Confirm Password"));

        newUserCard.add(name);
        newUserCard.add( loginNamePanel);
        newUserCard.add(pword);
        newUserCard.add(confirmpwd);
        newUserCard.add(submit);
        displayUsers(users);
      // JSplitPane sw=new JSplitPane
        JSplitPane splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,newUserCard,userPane);
        //splitPane.setDividerLocation(0.8);
        splitPane.setOneTouchExpandable(true);
        //splitPane.repaint();
        userPane.setMaximumSize(new Dimension(10,20));
        //adminCard.re

        adminCard.add(splitPane);
        adminCard.validate();
        submit.addActionListener(this);
    } 

if(loginState==false && users.size()!=0){
    JTextArea previlege=new JTextArea("Please login in order to create new users");
                adminCard.add(previlege);
                adminCard.validate();

            }
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 2
    1) For better help sooner, post a [MCTaRE](http://stackoverflow.com/help/mcve) (Minimal Complete Tested and Readable Example). 2) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. 3) A single blank line of white space in source code is *always* enough. Blank lines after `{` or before `}` are also typically redundant. 4) `previlege` should be spelled `privilege`. – Andrew Thompson Mar 06 '14 at 17:16
  • Did you ever find a solution for your problem? If so don't forget to upvote and accept an answer. If none of the current answers help, you can always post your own answer and accept it. That way it helps people who have the same problem as you in the future. – Rudi Kershaw Mar 24 '14 at 14:21

1 Answers1

0

Try calling repaint(); as well, when you call validate(); Any time you do a remove(); or a removeAll();, you should call both.

adminCard.validate();
adminCard.repaint();

A link to an earlier post on the issue

Community
  • 1
  • 1
Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77