File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Missing Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Missing Components" Watch "Missing Components" New topic

Missing Components

Al Wells
Ranch Hand

Joined: Apr 18, 2005
Posts: 87
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

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
Al Wells
Ranch Hand

Joined: Apr 18, 2005
Posts: 87
Thanks Ernest. That explains a lot.

Got it working.
I agree. Here's the link:
subject: Missing Components
jQuery in Action, 3rd edition