Reputation: 57
I'm trying to create a panel that has information on it.
I've tried using the setBorderLayout
to add the labels with the information to certain areas of the panel, but I know this doesn't work as it just overwrites what I already had before.
Here is an example from my code:
final JFrame fr = new JFrame("ATCGUI");
fr.setLayout(new BorderLayout());
JTabbedPane tabbedPane = new JTabbedPane();
JPanel tab1 = new JPanel();
tab1.setLayout(new BorderLayout());
tabbedPane.addTab("Airport", tab1);
JLabel labelAirportName = new JLabel(airportInfo[0]);
tab1.add(labelAirportName, BorderLayout.NORTH);
JLabel labelAirportCodeStatic = new JLabel("Code:");
JLabel labelAirportLocationStatic = new JLabel("Location:");
JLabel labelAirportCoordinatesStatic = new JLabel("Coordinates:");
JLabel labelAirportAltitudeStatic = new JLabel("Altitude:");
JLabel labelAirportTimezoneStatic = new JLabel("Timezone:");
JLabel labelAirportICAOStatic = new JLabel("ICAO:");
tab1.add(labelAirportCodeStatic, BorderLayout.WEST);
tab1.add(labelAirportLocationStatic, BorderLayout.WEST);
tab1.add(labelAirportCoordinatesStatic, BorderLayout.WEST);
tab1.add(labelAirportAltitudeStatic, BorderLayout.WEST);
tab1.add(labelAirportTimezoneStatic, BorderLayout.WEST);
tab1.add(labelAirportICAOStatic, BorderLayout.WEST);
This ends up creating something like this:
When I am aiming for something that looks more like this:
I created this with the SwingUI designer but due to compatibility I am switching over to just Swing
Upvotes: 0
Views: 277
Reputation: 57
Following the Oracle Swing tutorial linked by maloomeister https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
I was able to create the layout I wanted by mixing BorderLayout and GridLayout.
Upvotes: 1