Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jbutton  RSS feed

 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JFrame with a menubar and submenus and a text field. I am trying to add three buttons to the empty part of the frame, below the textarea. i am alos using getContentPane().add(button1 (and 2 and 3)). Each button overlaps the other and you only see the last one in the code. any suggestions.
thanks
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keiyia,
By default JFrame uses a BorderLayout. Not familiar with layouts? Find out about them here.
Regards,
Manfred.
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manfred,
Should I change it to a panel.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could put the buttons on a panel and the panel on the frame. That should work.
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um...any suggestions on how to do that. I always use frames.
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. I set the layout for the content pane to BoxLayout. Thanks
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are always multiple ways of doing it box like you found out. Putting your components onto panels then placing the panels on the frame. Headers in the north, the buttons in the south your main component panel in the center. Gridbaglayout. It all comes down to understanding the layouts.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!