• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Missing Components

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest. That explains a lot.

Got it working.
reply
    Bookmark Topic Watch Topic
  • New Topic