The content pane of a JFrame
has a BorderLayout
. If you place a component in a BL with no constraints it ends up in the CENTER
. The center can only display one component.
For an immediate effect, I suggest:
f.add(top, BorderLayout.PAGE_START);
f.add(mid);
f.add(bot, BorderLayout.PAGE_END);
Other points.
- Take out
f.setSize(500, 500);
and callpack()
immediately beforesetVisible(true)
- For a better way to end the GUI, change
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tof.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
in.setVisible(true);
Except for the frame itself, take these out. A component automatically becomes visible when it is added to a top level container and that container is itself made visible.- Change
public class EncDecExample extends JFrame
topublic class EncDecExample
This code keeps a reference to a frame, and that is the right way to go.