Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

220 HOUR 16:Building a Complex User Interface


. JScrollPane(Component)—Create a scroll pane that contains the
specified user interface component.
. JScrollPane(Component, int, int)—Create a scroll pane with the
specified component, vertical scrollbar, and horizontal scrollbar.


The integer arguments to these constructors determine how scrollbars are
used in the pane. Use the following class variables as these arguments:

. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDEDor
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
. JScrollPane.VERTICAL_SCROLLBAR_NEVERor
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
. JScrollPane.VERTICAL_SCROLLBAR_ALWAYSor
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS


If you have created a scroll pane without a component in it, you can use
the pane’s add(Component)method to add components. After you have
finished setting up a scroll pane, it should be added to a container in place
of the component.
To see an application that includes a scroll pane, enter Listing 16.1 into a
new empty Java file named MailWriterand save the file.

LISTING 16.1 The Full Text of MailWriter.java
1: importjavax.swing.*;
2: importjava.awt.*;
3:
4: public classMailWriter extendsJFrame {
5:
6: public MailWriter() {
7: super(“Write an E-Mail”);
8: setLookAndFeel();
9: setSize(370, 270);
10: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
11: FlowLayout flow = new FlowLayout(FlowLayout.RIGHT);
12: setLayout(flow);
13:
14: JPanel row1 = new JPanel();
15: JLabel toLabel = new JLabel(“To:”);
16: row1.add(toLabel);
17: JTextField to = new JTextField(24);
18: row1.add(to);
19: add(row1);
20:
21: JPanel row2 = new JPanel();
Free download pdf