149k views
2 votes
30) Which Layout Manager type would you use if you want GUI components to be placed in 2 columns

over 5 rows?
a) FlowLayout
b) BorderLayout
c) BoxLayout
d) GridLayout
e) TabbedPane

1 Answer

1 vote

Final answer:

The correct Layout Manager type to use if you want GUI components to be placed in 2 columns over 5 rows is GridLayout.

Step-by-step explanation:

The correct Layout Manager type to use if you want GUI components to be placed in 2 columns over 5 rows is GridLayout.

GridLayout arranges components in a grid of cells, where each cell can contain only one component. In this case, you would create a GridLayout with 5 rows and 2 columns.

Here's an example of how you would use GridLayout to achieve this:

import javax.swing.*;

public class GridLayoutExample {

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel(new GridLayout(5, 2));

// Add your components to the panel

frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}

User Beresfordt
by
7.6k points