50.8k views
0 votes
35) What is wrong with the following message to create a BoxLayout for the JPanel jp?

jp.setLayout(new BoxLayout(BoxLayout.X_AXIS));
a) X_AXIS is not a valid constant for BoxLayout, it should instead be HORIZONTAL
b) Aside from X_AXIS, the constructor also requires a Dimension to determine the size of
the Box
c) Aside from X_AXIS, the constructor also needs a command regarding horizontal glue as
in createHorizontalGlue( )
d) The BoxLayout constructor is lacking a reference to the container that the BoxLayout
manager will govern
e) There is nothing wrong with it at all

1 Answer

3 votes

Final answer:

The correct answer is option a) X_AXIS is not a valid constant for BoxLayout, it should instead be HORIZONTAL.

Step-by-step explanation:

The correct answer is option a) X_AXIS is not a valid constant for BoxLayout, it should instead be HORIZONTAL. The BoxLayout class in Java Swing provides different constants to create different types of layouts. The correct constant to create a horizontal layout is BoxLayout.X_AXIS. Therefore, the correct code to create a BoxLayout for the JPanel jp would be jp.setLayout(new BoxLayout(jp, BoxLayout.X_AXIS));

User Chris Vilches
by
8.3k points