Only one component shows up in JFrame

The content pane of a JFrame has a BorderLayout. If you place a component in a BL with no constraints it ends up in the CENTER. The center can only display one component. For an immediate effect, I suggest: f.add(top, BorderLayout.PAGE_START); f.add(mid); f.add(bot, BorderLayout.PAGE_END); Other points. Take out f.setSize(500, 500); and call pack() immediately before … Read more

Providing white space in a Swing GUI

Using various LayoutManagers one can provide spacing between various components. 1.) BorderLayout : Overloaded Constructor : BorderLayout(int horizontalGap, int verticalGap) Getter and setter methods For Horizontal Spacing : BorderLayout.getHgap() and BorderLayout.setHgap(int hgap) For Vertical Spacing : BorderLayout.getVgap() and BorderLayout.setVgap() 2.) FlowLayout : Overloaded Constructor : FlowLayout(int align, int hgap, int vgap) Getter and setter methods … Read more

How to add JTable in JPanel with null layout?

Nested/Combination Layout Example The Java Tutorial has comprehensive information on using layout managers. See the Laying Out Components Within a Container lesson for further details. One aspect of layouts that is not covered well by the tutorial is that of nested layouts, putting one layout inside another to get complex effects. The following code puts … Read more