Java Reference
In-Depth Information
Don't think of it as adding scrollbars to the table. Rather, we're putting
the table into a container that has scrollbars, and this container is smart enough
to retrieve and display the table's header separately from the table (thus, the
table's data scrolls but the header stays put).
Here, in one step, we create the JScrollPane object and initialize it with
the JTable that we want to be scrolled over.
212 retval = new JScrollPane(list);
Think of the JScrollPane as a window with scrollbars through which
we can view the JTable . It has the convenient side effect of taking care of the
table's heading for us. Without the scroll pane (e.g., if we just put the JTable
in a JPanel ) we'd get only the data and no heading, unless we also did a lot of
extra work using other objects and method calls.
It is possible to set the JScrollPane to show horizontal as well as vertical
scrollbars. Those scrollbars can be made to be always or never visible, or visible
only as needed. Setting a scrollbar to “never visible” effectively turns off any
scrolling in that direction. Use the setHorizontalScrollBarPolicy() and
setVerticalScrollBarPolicy() methods to set the value to one of:
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
Scroll panes can scroll over any GUI element—that is, any Component
object, not just tables. For more information on scroll panes, be sure to refer
to the Javadoc pages.
16.7.2.13
We have covered most of the code in the main GUI functionality—the way it
initially creates its parts and lays them out for display. We have examined the
JTable in some considerable detail and looked at a few actions associated with
buttons. Now we need to get to the user interaction that allows us to create a
new account.
Lines 244-268 of BudgetPro are the action that gets attached to the
button for creating a new subaccount.
Dialogs
Search WWH ::




Custom Search