aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Missing Components" Watch "Missing Components" New topic
Author

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
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Missing Components
 
Similar Threads
Display information from a database in a custom made GUI
2D Array Help
Help with a simple login Gui
Problem with custom painting and multiple JPanel
Updating values in a jTable