1

Currently I have a JFrame 'window' with the layout set to BorderLayout. I have a panel for the west and center sections, with two alternating panels for south. In the west section I have 5 labels. In the center section I have 5 JTextField components. And in the south section i want to alternate between two panels (both FlowLayout) &(each one holds 2 separate buttons).

Right now I initialize and the south section has the correct two buttons, but when i call my event action listener only half of the method is called correctly. Behind the scenes i have the menu item connected to the listener, and it seems to work correctly. the clear text method works but changing the south panel does not

here are the panels and frame being initialized(they are initialized in the class constructor):

    myWindow = new JFrame();
    myWindow.setLayout(new BorderLayout());
    myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    sPanel1.add(prevButton);
    sPanel1.add(nextButton);
    sPanel2.add(okButton);
    sPanel2.add(cancelButton);

    myWindow.add(sPanel1, BorderLayout.SOUTH);
    myWindow.add(wPanel, BorderLayout.WEST);
    myWindow.add(cPanel, BorderLayout.CENTER);
    //so here, at this line, i have tried the adding sPanel2 at the south position,
    //after i have added sPanel1.  The result is that sPanel2 overrides sPanel1 (like i 
    //assumed it would).  However, the same doesnt work in the editAddEvent method    
     //below. both lines are called but only the cleartextfields method works.  
     //why is this?

  public class myEvent implements ActionListener{   
     @Override
     public void actionPerformed(ActionEvent arg0) {
        myWindow.add(sPanel2, BorderLayout.SOUTH);
        clearTextFields();  
        myWindow.revalidate();
        myWindow.repaint();
        Container content = myWindow.getContentPane();
        content.revalidate();
        content.repaint();
     }
}

public void clearTextFields(){
    fNameTxt.setText("");
    mNameTxt.setText("");
    lNameTxt.setText("");           
}

the clear textfields method works perfectly, it clears my JTextFields

4

0 回答 0