output : i am getting a window at the left corner of the screen and a print "hello" in the middle of the window.
question: 1. how can i move the window to my desired position , say at the middle of the screen.
2. why only the print "hello" . where the button has gone ? a button has border . but i dont see border here ....only the print "hello" at the middle of the window !! . so how can i get borders around the button so that it looks really a button. thanx
The answers to your questions are in the JWindow api:
1 - position the window with setLocation or setLocationRelativeTo. The use of setLocation is discussed near the top.
2 - also near the top it says that BorderLayout is the default layout for a JWindow. When you add a component to the center section or a border layout it expands to fill the available space in both horizontal and vertical dimensions. So the button fills the entire window with its borders at the edge of the window. Click on it to see. The solution is to add the button to a JPanel and add the panel to the center section. The panel will fill the center section and allow the button to remain at its preferred size. Check the BorderLayout api for more information about using it and how it works.