• Post Reply Bookmark Topic Watch Topic
  • New Topic

why no border around the button !!

 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!