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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

374Chapter 16Getting in the Swing of Things: Designing a GUI for BudgetPro• C<strong>on</strong>tainers to hold GUI objects, such as JFrame for our outermost window,JPanel for an assortment of objects, and JScrollPane for viewinglarger objects through a scrollable window.• Labels (JLabel class) to hold either a short bit of text, or an image, orboth; it can even take snippets of HTML, for fancier formatting andcoloring of text.• Butt<strong>on</strong>s (JButt<strong>on</strong> class) to which we attached acti<strong>on</strong>s—the code fragmentsthat get called when the butt<strong>on</strong>s get pushed; a butt<strong>on</strong> could havetext and/or an image displayed in it.• Acti<strong>on</strong>s—whether for butt<strong>on</strong>s or selecti<strong>on</strong>s (or other triggers yet to bediscussed), an acti<strong>on</strong> is the code that runs when the event (e.g., butt<strong>on</strong>press) occurs.• Text fields (JTextField class) to take small amounts of user input; ourapplicati<strong>on</strong> didn’t need the other types of text fields (JTextArea andJTextPane) useful for much more extensive user input.•A JTable instance and its associated TableModel, Selecti<strong>on</strong>Model, andTableCellRenderer which provide tremendous flexibility and c<strong>on</strong>trolover table behavior and c<strong>on</strong>tents.•A JDialog instance with custom c<strong>on</strong>tent, to allow for multiple user inputs;the dialog comes and goes with its visibility; since it’s a modal dialog,when it is visible, it “hogs” all the user interacti<strong>on</strong>s; it is possible to maken<strong>on</strong>modal dialogs, but our applicati<strong>on</strong> didn’t need to.• LayoutManagers for our JFrame and JPanels, used to place objectswithin a c<strong>on</strong>tainer with various algorithms for placement and expansi<strong>on</strong>.16.9WHAT YOU STILL DON’T KNOWOne could spend a career learning the vagaries of layout managers, especiallythe way they interact (e.g., a BoxLayout inside the various regi<strong>on</strong>s of aBorderLayout). There is still an art to getting all the interacti<strong>on</strong>s right; it’soften quickest to prototype the layout before you get too committed to a particularlayout. Also, putting objects into c<strong>on</strong>tainers can help you subdivide thelayout problem into more manageable pieces. You can even go so far as to writeyour own LayoutManager, a topic we do not cover in this book.The informati<strong>on</strong> that we display in the JTable in our example is hierarchical.Swing provides a JTree object for displaying such informati<strong>on</strong>. Like a

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

Saved successfully!

Ooh no, something went wrong!