How to show different pages from the center element of JFrame (having set to BorderLayout)

Here is a mcve demonstrating how you could use CardLayout as suggested by Andrew Thompson: import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class GuiController extends JFrame { private boolean isRedShowing; public GuiController(){ setTitle(“CardLayout Demo”); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); CentreFrameController centreFrameController = new CentreFrameController(); centreFrameController.showRedPane(); isRedShowing = true; setLayout(new BorderLayout()); … Read more

Why does this GridBagLayout not appear as planned?

I am afraid the desired layout is not so simple with simple GridBagLayout restriction. GBL does not respect proportions with gridwidth. It means it can’t detect 2/3 of component’s width. So if you define c1 (gridwidth=2) c2 (gridwidth=1) c3 (gridwidth=3) Expecting to get |****|**| |*******| The result will be |**|**| |*****| The camickr’s example works … Read more

Eclipse WindowBuilder, overlapping JPanels

You might also want to look at OverlayLayout, seen here. It’s not included in the conventional gallery, but it may be of interest. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.OverlayLayout; /** @see http://stackoverflow.com/a/13437388/230513 */ public class OverlaySample { public static void main(String args[]) { JFrame frame = new … Read more

JPanel & components change position automatically

I think the original (non-broken) layout looks quirky and would make it difficult for the end user to follow the rows and labels/fields. I suggest instead using a GroupLayout to right align the labels, and left align the fields that contain the values. Like this: import java.awt.*; import java.util.HashMap; import java.util.Map; import javax.swing.*; class TwoColumnLayoutWithHeader … Read more