posted 22 years ago
hi sonu,
first of all, i have to tell u that the BorderLayout doesn't not respect the sizes of its components! so when u add a component to a container having BorderLayout, the component's size will be set according to the space available in the container. if u add 2 components, the available space will be divided equally among them and if u add one component only, the whole of the conatiner's size will be given to the component! thats what is exactly happening in your case. the JPanel gets all the space of the JFrame. and since in a JPanel, the components are laid out in a FlowLayout fashion, the components are displayed from top. so u see the JTextField and the JButton on top.
if u have only one component to add to a conatiner and want the component to be at the center, use either a GridBagLayout manager or don't use any layout, i.e. set the layout of the container to null and then place the component accordingly.
i have used null layout.
here's the code u want.
///
hope thats what u want.
rgds
Shashi