• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

why no border around the button !!

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.

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.
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.
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic