I wrote a simple program to see the effects of the add and remove methods in java and for whatever reason the following code does not display the OK button. Can anyone tell me why? I am thoroughly confused as it should work just fine.
import javax.swing.*;
public class MyFrameWithComponents {
public static void main(String[] args){
JFrame frame = new JFrame("Adding and removing components.");
JButton OK = new JButton("OK");
JButton Cancel = new JButton("Cancel");
frame.add(OK);
frame.add(Cancel);
frame.remove(Cancel);
frame.setSize(400 , 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}