1 / 8

User Interface Components

User Interface Components. Layout. Placement of UI components in a window Size & Position Each component occupies a rectangular region in the window Components are told where and how big they are Each component has a P referred size Minimum size Maximum size. Layout.

mercia
Download Presentation

User Interface Components

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. User Interface Components

  2. Layout • Placement of UI components in a window • Size & Position • Each component occupies a rectangular region in the window • Components are told where and how big they are • Each component has a • Preferred size • Minimum size • Maximum size

  3. Layout • Ideally, each component will be assigned its preferred size • To accommodate the current window size, a component may get more or less space than it prefers • Window resize behavior • When the user resizes a window, the sizes and positions of components in the window must be adjusted to accommodate the new size

  4. Panels • The area of a frame window can be divided into rectangular regions called “panels” • Implemented by the JPanel class • Each panel contains sub-components • A panel is a “container” component, because it contains other components • Component Tree • Frame window at the root • Panels for the interior nodes • Simple components (e.g., buttons, text fields, etc.) at the leaves • Each panel’s components are lain out separately

  5. Layout Managers • There are different algorithms for laying out components in a panel • Each panel has a “layout manager” object that is responsible for deciding the sizes and positions of the panel’s components • Java provides several LayoutManager classes that implement different layout algorithms • BorderLayout, BoxLayout, CardLayout, FlowLayout, GridLayout, GridBagLayout, GroupLayout, SpringLayout, …

  6. Simple Layout • FlowLayout • Example: FlowTest • BorderLayout • Example: BorderTest • GridLayout • Example: GridTest

  7. Built-in Components • Guide to Swing Components • Component Events • User actions generate events • Listeners respond to events • Example: Font Selector • ActionListener, ChangeListener • Listeners Supported by Swing Components

  8. Design Exercise: Simple Web Browser • Web Browser • Web Browser (Refactored)

More Related