Java Swing Interview Questions and Answers - 3

Question: 11

Name Components subclasses that support painting?

The Canvas,

Frame,

Panel and

Applet classes support painting.

Question: 12

What is the preferred size of a component?

The preferred size of a component is the minimum component size that will allow the component to display normally.

Question: 13

Which containers use a Flow Layout as their default layout?

The Panel and Applet classes use the Flow Layout as their default layout.

Question: 14

How do you handle opening of database, file or network connection on a click of button?

You should not do this operation in EDT thread instead spawn a new thread from action listener or button and disable the button until operation gets completed to avoid resubmitting request.

Only condition is that your GUI should always be responsive no matter what happens on network connection or database connection because these operations usually take time.

Question: 15

What method is used to specify a container’s layout?

The setLayout() method is used to specify a container’s layout.

For example, setLayout(new Flow Layout()); will be set the layout as Flow Layout.

Related Questions