• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Missing Components

 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I converted a panel to a frame to make the flow of the program a little
better. But, only the first panel and the last label of this class are
now showing on the frame (the other panel is not). What am I missing?

I have some things being put in panels and some things placed directly
on screen. The last label ('thirdWarn') is displaying and the first panel
(eqTypePanel) is showing and nothing else is.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whereas a JPanel has a FlowLayout for a layout manager by default, a JFrame has a BorderLayout. Everything you just call add() to add to a JPanel gets displayed, one next to the other. But a BorderLayout uses specific named positions on the screen, and if you just call add() with one argument, it uses the default position, which is BorderLayout.CENTER. Each component replaces the last one, instead of them all being displayed together.

If you had a layout that already worked and all you did here was change it to use a JFrame directly instead of a JPanel, then you might simply precede all the GUI code with setLayout(new FlowLayout()), which will make the JFrame act like your JPanel used to.
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest. That explains a lot.

Got it working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic