13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

370Chapter 16Getting in the Swing of Things: Designing a GUI for BudgetProD<strong>on</strong>’t think of it as adding scrollbars to the table. Rather, we’re puttingthe table into a c<strong>on</strong>tainer that has scrollbars, and this c<strong>on</strong>tainer is smart enoughto retrieve and display the table’s header separately from the table (thus, thetable’s data scrolls but the header stays put).Here, in <strong>on</strong>e step, we create the JScrollPane object and initialize it withthe JTable that we want to be scrolled over.212 retval = new JScrollPane(list);Think of the JScrollPane as a window with scrollbars through whichwe can view the JTable. It has the c<strong>on</strong>venient side effect of taking care of thetable’s heading for us. Without the scroll pane (e.g., if we just put the JTablein a JPanel) we’d get <strong>on</strong>ly the data and no heading, unless we also did a lot ofextra work using other objects and method calls.It is possible to set the JScrollPane to show horiz<strong>on</strong>tal as well as verticalscrollbars. Those scrollbars can be made to be always or never visible, or visible<strong>on</strong>ly as needed. Setting a scrollbar to “never visible” effectively turns off anyscrolling in that directi<strong>on</strong>. Use the setHoriz<strong>on</strong>talScrollBarPolicy() andsetVerticalScrollBarPolicy() methods to set the value to <strong>on</strong>e of:JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDEDJScrollPane.HORIZONTAL_SCROLLBAR_NEVERJScrollPane.HORIZONTAL_SCROLLBAR_ALWAYSScroll panes can scroll over any GUI element—that is, any Comp<strong>on</strong>entobject, not just tables. For more informati<strong>on</strong> <strong>on</strong> scroll panes, be sure to referto the Javadoc pages.16.7.2.13 DialogsWe have covered most of the code in the main GUI functi<strong>on</strong>ality—the way itinitially creates its parts and lays them out for display. We have examined theJTable in some c<strong>on</strong>siderable detail and looked at a few acti<strong>on</strong>s associated withbutt<strong>on</strong>s. Now we need to get to the user interacti<strong>on</strong> that allows us to create anew account.Lines 244–268 of BudgetPro are the acti<strong>on</strong> that gets attached to thebutt<strong>on</strong> for creating a new subaccount.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!