Presentation is loading. Please wait.

Presentation is loading. Please wait.

SWING 101.0. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:

Similar presentations


Presentation on theme: "SWING 101.0. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:"— Presentation transcript:

1 SWING 101.0

2 IF YOU GET LOST - IMPORTANT LINKS  Swing articles: http://java.sun.com/javase/technologies/desktop/articles.jsp http://java.sun.com/javase/technologies/desktop/articles.jsp  Swing Architecture: http://java.sun.com/products/jfc/tsc/articles/architecture/ http://java.sun.com/products/jfc/tsc/articles/architecture/  Visual Editor for Eclipse: http://wiki.eclipse.org/VE/Update#Online_Install http://wiki.eclipse.org/VE/Update#Online_Install  Oracle Swing tutorial: http://download.oracle.com/javase/tutorial/uiswing/ http://download.oracle.com/javase/tutorial/uiswing/  Stack Overflow: http://stackoverflow.com/ http://stackoverflow.com/  Basic Swing tutorial: http://zetcode.com/tutorials/javaswingtutorial/ http://zetcode.com/tutorials/javaswingtutorial/

3 SWING COMPONENTS HIERARCHY  Tutorial  http://www.docstoc.com/docs/33446046/Java-Swing# http://www.docstoc.com/docs/33446046/Java-Swing#  Components  http://download.oracle.com/javase/tutorial/ui/features/compWin.html http://download.oracle.com/javase/tutorial/ui/features/compWin.html  Layout  http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html

4 PAINT AND LAYOUT  Swing components painting and layout order  First you set properties on components  Then swings lays outs components  Then paints them  Note: until the top level container has been set to visible and laid out you can not know the size and location of your component  paint, repaint, invalidate, validate  paint() – paints the component. Invoked internally by Swing – DO NOT USE  repaint() – instructs Swing to paint the given region when the “time is right” – Safe to use  validate() –checks if the container (and its children) have been changed and if so instructs Swing to perform a re-layout  invalidate() –marks a container as invalid but does not perform a re-layout

5 CONTAINERS  The main containers are: JPanel, JSplitPane, JScrollPane and JTabbedPane  Have properties that defines their looks and behavior (just like components)  Don’t have data models  Have events (mouse events, size changes events, etc.)  Adding components– add the component to the children list of the container and set the component parent to be the container  When you add a component you link it to the container – not create a copy of it in the container  getParent() – for containers and components  getChildren() – for containers only  Each component or container has a single parent

6 LAYOUT MANAGER  Only valid for containers  Automatically set the size and location of all the child components in the container  Different layout algorithms – some have properties (for example: gap between components)  Some require additional data for each child component – that data should be added in advanced when adding a component to a container  Settings size constrains (size, preferred, minimum, maximum)  http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html

7 COMPLEX LAYOUT  A container an contains child containers (same as components)  When it resizes – all of its child containers will be resized as well and then re-layout their child component recursively  You can mix different layout algorithms (for example: a JPanel with Border Layout that contains 3 JPanels with Flow Layout each)

8 ACTIONS  Just like the interface Runnable – this is Swing’s way to pass “a parameter of a method to a component” – meaning, pass some code to execute when a common event occurs  Actions are not JComponents (not UI objects)  The same action instance can be passed to several UI components (menu item, JButton, etc.)  Actions have properties for the component that will use them:  Label  Icon  Tooltip

9 DIALOGS  JDialogs are Top-Level containers  Open a dialog that displayed some content (like JFrame)  To set custom content – add it to the dialog’s content pane  After calling setVisible(true) on a dialog – no events are dispatched to the rest of the UI components (except in the dialog itself)  You can customize the dialog’s buttons (change the number of buttons, the text on each button, etc.)  http://download.oracle.com/javase/tutorial/uiswing/components/dialog.ht ml http://download.oracle.com/javase/tutorial/uiswing/components/dialog.ht ml

10 GUI EDITORS  Great for all the things in the world… except when you need to change a component programmatically  Here are some recommendations:  NetBeans  JFormDesigner  Eclipse UI editor  Another issue – some editors might add dependencies on external Jars (which you’ll need to bundle with your complied code in order for it to execute)  Adding external jars to project

11 OTHER SWING STUFF  Menus  Renderers (and Editors)  How to set native look and feel  Selection events, change events(Optional)


Download ppt "SWING 101.0. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:"

Similar presentations


Ads by Google