Creating Professional Swing UIs Using the NetBeans GUI Builder

Similar documents
JavaFX. Getting Started with JavaFX Scene Builder Release 1.1 E

Tree and Data Grid for Micro Charts User Guide

Microsoft How to Series

Human-Computer Interaction IS4300

Ninja Menus extension for Magento 2

Using NetBeans IDE for Desktop Development. Geertjan Wielenga

Windows and Events. created originally by Brian Bailey

Create ruler guides. Create a ruler guide

Creating Page Layouts 25 min

I.1 Introduction Matisse GUI designer I.2 GroupLayout Basics Sequential and Parallel Arrangements sequential horizontal orientation

Lehigh University Library & Technology Services

The Definitive Guide to. NetBeans Platform 7. Heiko Bock. Apress*

How to set up a local root folder and site structure

VisualPST 2.4. Visual object report editor for PowerSchool. Copyright Park Bench Software, LLC All Rights Reserved

Excel 2013 for Beginners

ekaizen Lessons Table of Contents 1. ebook Basics 1 2. Create a new ebook Make Changes to the ebook Populate the ebook 41

Using OMNIS Studio. OMNIS Software

Nauticom NetEditor: A How-to Guide

Table Basics. The structure of an table

Sema Foundation ICT Department. Lesson - 18

Creating Web Pages with SeaMonkey Composer

Assignment 1. Application Development

Step 1 Download and Install KompoZer Step by step instructions to build your first web page using KompoZer web editor.

NOMADS Enhancements v7.50 & v8.00. Presented by: Yvonne Sampson

IBM Forms V8.0 IBM Forms Classic - Forms Designer IBM Corporation

Designer Reference 1

BASICS OF MOTIONSTUDIO

GUI Components: Part 1

Insert/Edit Image. Overview

How to lay out a web page with CSS

Getting Started Guide

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Unit D Lecture Notes Word 2003

Excel Select a template category in the Office.com Templates section. 5. Click the Download button.

Interaction Style Categories. COSC 3461 User Interfaces. Windows. Window Manager

Reference Services Division Presents. Microsoft Word 2

How to use the ruler, grid, guides, and the Align panel

Java Application Development

Word Tutorial 3. Creating a Multiple- Page Report COMPREHENSIVE

Basic Concepts. Launching MultiAd Creator. To Create an Alias. file://c:\documents and Settings\Gary Horrie\Local Settings\Temp\~hh81F9.

AutoCAD 2009 User InterfaceChapter1:

SMART Meeting Pro 4.2 personal license USER S GUIDE

USER GUIDE. MADCAP FLARE 2017 r3. QR Codes

MS WORD INSERTING PICTURES AND SHAPES

1 Introduction to Using Excel Spreadsheets

Managing Content with AutoCAD DesignCenter

Technology for Merchandise Planning and Control

Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR

WIMP Elements. GUI goo. What is WIMP?

Overview of the Adobe Dreamweaver CS5 workspace

SETTINGS AND WORKSPACE

Forms/Distribution Acrobat X Professional. Using the Forms Wizard

Microsoft Office Excel 2007: Basic. Course Overview. Course Length: 1 Day. Course Overview

Chapter 1 Introduction to Dreamweaver CS3 1. About Dreamweaver CS3 Interface...4. Creating New Webpages...10

Introduction to Microsoft Word 2008

Excel 2007 New Features Table of Contents

A Guide to Using WordPress + RAVEN5. v 1.4 Updated May 25, 2018

The MVC Design Pattern

Chapter 7 Inserting Spreadsheets, Charts, and Other Objects

Document Editor Basics

Website Management with the CMS

ADOBE TRAINING CS6 PHOTOSHOP BASICS: EDITING PHOTOS & WORKING WITH TEXT - 1

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Status Bar: Right click on the Status Bar to add or remove features.

Building the GUI ILOG Views GUI Builder

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

What can Word 2013 do?

Chart User Interface (v 2.0) Feature Specification

Low fidelity: omits details High fidelity: more like finished product. Breadth: % of features covered. Depth: degree of functionality

L E S S O N 2 Background

Excel 2013 Intermediate

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

Chapter 2 The Design Window

Forte for Java (Community Edition) QuickStart Guide

Introduction to the JAVA UI classes Advanced HCI IAT351

Guide to Parallel Operating Systems with Windows 7 and Linux

TSM Report Designer. Even Microsoft Excel s Data Import add-in can be used to extract TSM information into an Excel spread sheet for reporting.

Seng310 Lecture 8. Prototyping

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

How to Prepare Your Cards for Press Using Scribus

button Double-click any tab on the Ribbon to minimize it. To expand, click the Expand the Ribbon button

Create a Scrapbook Page

Using PowerPoint in Effective Presentations

How to Create Greeting Cards using LibreOffice Draw

DEVELOPING DATABASE APPLICATIONS (INTERMEDIATE MICROSOFT ACCESS, X405.5)

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

CS 4300 Computer Graphics

Excel Core Certification

Learning to use the drawing tools

Starting Excel application

Publisher 2016 Foundation SAMPLE

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Chapter 5. Inserting Objects. Highlights

SMART Meeting Pro PE 4.1 software

Microsoft Publisher 2013 Foundation. Publisher 2013 Foundation SAMPLE

Creating & Using Tables

Publisher 2016 Foundation. North American Edition SAMPLE

MODIFYING CIRCULATION WINDOW DISPLAYS

Creating electrical designs

Transcription:

Creating Professional Swing UIs Using the NetBeans GUI Builder Tomas Pavek, Jan Stola, Scott Violet Sun Microsystems http://www.netbeans.org http://swinglabs.dev.java.net TS-4916 Copyright 2006, Sun Microsystems, Inc., All rights reserved. 2006 JavaOne SM Conference Session TS-4916

Goal of This Presentation Learn how to easily create professional Swing UIs using the NetBeans GUI Builder (formerly code-named Matisse) 2006 JavaOne SM Conference Session TS-4916 2

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 3

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 4

Introduction Why to use a GUI builder Visual interaction (WYSIWYG) Simplify layout design Easy manipulation and customization of components Quick prototyping Consistency Generating code, binding to UI Ease of maintenance 2006 JavaOne SM Conference Session TS-4916 5

NetBeans GUI Builder Introduction Main features Supports AWT/Swing Based on JavaBeans architecture Allows designing layout in a natural way One-way code generator Using standard JDK software classes 2006 JavaOne SM Conference Session TS-4916 6

NetBeans GUI Builder Introduction What will we present? Special NetBeans IDE build for JavaOne SM conference (upcoming 6.0 version) Update for NetBeans 5.0/5.5 IDE will be available http://form.netbeans.org/javaone 2006 JavaOne SM Conference Session TS-4916 7

DEMO NetBeans GUI Builder Introduction 2006 JavaOne SM Conference Session TS-4916 8

NetBeans GUI Builder Introduction Basic tips Note the Source/Design view switch in toolbar Use Inspector to explore hierarchy of components Use preview to see live GUI quickly Design This Container action is useful for: Standalone containers Panels in tabbed pane A panel in a scroll pane Note you can design UI without subclassing a visual class 2006 JavaOne SM Conference Session TS-4916 9

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 10

UI Design Goals Swing GUI Specifics Different platforms, look and feels, localization Component sizes and proportions may change Dynamic behavior We want resizability most of GUI forms UI is expressed by code No common resource format Layout can't be modified independently (localized) 2006 JavaOne SM Conference Session TS-4916 11

UI Design Goals Requirements on Java Technology GUI Platform (look and feel) independence Localization independence Scale with size, font, and resolution Follow UI guidelines Visual consistency UI separated from application logic 2006 JavaOne SM Conference Session TS-4916 12

Platform Independence Common mistakes in cross platform UI design Using absolute sizes or positions Relying on relative proportions of components Implicit position dependencies Hard coded strings Hard coded fonts and colors Hard coded left to right orientation 2006 JavaOne SM Conference Session TS-4916 13

Cross Platform UI Example: absolute sizes and positions 2006 JavaOne SM Conference Session TS-4916 14

Cross Platform UI Example: absolute sizes and positions 2006 JavaOne SM Conference Session TS-4916 15

Cross Platform UI Example: missing resizable element 2006 JavaOne SM Conference Session TS-4916 16

Cross Platform UI Example: missing resizable element 2006 JavaOne SM Conference Session TS-4916 17

Cross Platform UI Complex example: insidious grid 2006 JavaOne SM Conference Session TS-4916 18

Cross Platform UI Complex example: insidious grid 2006 JavaOne SM Conference Session TS-4916 19

Cross Platform UI Complex example: insidious grid 2006 JavaOne SM Conference Session TS-4916 20

Cross Platform UI Complex example: insidious grid Mistakes: Relying on relative proportions of components Implicit position dependencies 2006 JavaOne SM Conference Session TS-4916 21

Cross Platform UI Example: hard coded font 2006 JavaOne SM Conference Session TS-4916 22

Cross Platform UI Example: hard coded font 2006 JavaOne SM Conference Session TS-4916 23

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 24

Cross Platform UI design in NetBeans IDE Layout designed once can run everywhere Matisse helps to avoid the cross platform mistakes Dynamic layout definition built behind the scene Relative positioning Adaptive spacing (gaps according to UI guidelines) Aligning (also supports baseline alignment) Resizing definition BiDi compliant Built-in internationalization support 2006 JavaOne SM Conference Session TS-4916 25

Cross Platform UI design in NetBeans IDE Can combine different layout managers Need not care about layout managers while in the default Free Design mode Using a layout manager still valid in some cases: Free Design not convenient for all types of layout May need full control over all aspects of the layout Invoke Customize Layout on a container with GridBagLayout for a helpful customizer Containers with Free Design and layout managers can be combined freely 2006 JavaOne SM Conference Session TS-4916 26

Good Design Practices Layout guidelines Follow the guidelines Matisse offers It is easy to make the components aligned right away Pay attention to the suggested alignment There can be more guidelines offered on close positions but with different alignment 2006 JavaOne SM Conference Session TS-4916 27

Good Design Practices Avoid the I have lots of space syndrome Snap components to preferred positions Draw components to container borders Reduce superfluous space What you see is really what you get 2006 JavaOne SM Conference Session TS-4916 28

Good Design Practices Default size and resizability Keep components in their default size, or make them resizable Design every container as resizable 2006 JavaOne SM Conference Session TS-4916 29

Good Design Practices Aligning actions You don t need to do everything via mouse There are aligning actions in toolbar and more actions in context menu 2006 JavaOne SM Conference Session TS-4916 30

Good Design Practices Layout design tips Matisse does not remember the absolute positions but relations between components Pay attention to anchors, lines of alignment, resizability Components may move to preserve the established relations 2006 JavaOne SM Conference Session TS-4916 31

DEMO Designing Layout 2006 JavaOne SM Conference Session TS-4916 32

Good Design Practices More design tips Use Space Around Component dialog to finetune gaps between components Gaps can also be resizable You can provide custom LayoutStyle implementation for runtime Use Set Same Size action to impose same width on related components (e.g., buttons) When dragging Use Shift to add multiple components Use Control to hold to a guideline Use Alt to suppress snapping on guidelines 2006 JavaOne SM Conference Session TS-4916 33

Matisse Behind the Scene New layout features in JDK 6 software GroupLayout brand new layout manager LayoutStyle responsible for spacing Swing Layout Extensions library used before Practical tips for manual coding: Can provide custom LayoutStyle implementation Can replace part of the layout dynamically Controlling visibility can show/hide components without affecting the layout 2006 JavaOne SM Conference Session TS-4916 34

GroupLayout Not intended for hand coding Can automatically add preferred gaps Uses LayoutStyle to determine preferred gaps Ability to align components along their baseline Finally! Each axis treated independently Must configure horizontal and vertical axis separately 2006 JavaOne SM Conference Session TS-4916 35

GroupLayout Groups Group Contains components and other groups Horizontal Group sets x and width Vertical Group sets y and height Two types of Groups Sequential Group Aligns contents one after another Parallel Group Aligns contents on top of each other Typically used in conjunction with sequential group along opposite axis 2006 JavaOne SM Conference Session TS-4916 36

Sequential Group Vertical Axis Horizontal Axis SequentialGroup hg = layout.createsequentialgroup(); hg.addcomponent(c1).addcomponent(c2).addcomponent(c3); layout.sethorizontalgroup(hg); 2006 JavaOne SM Conference Session TS-4916 37

Parallel Group Along One Axis Horizontal Axis Vertical Axis ParallelGroup hg = layout.createparallelgroup(); hg.addcomponent(c1).addcomponent(c2).addcomponent(c3); layout.sethorizontalgroup(hg); 2006 JavaOne SM Conference Session TS-4916 38

Parallel Group Used with a Sequential Group Horizontal Axis Vertical Axis ParallelGroup hg = layout.createparallelgroup(); hg.addcomponent(c1).addcomponent(c2).addcomponent(c3); layout.sethorizontalgroup(hg); SequentialGroup vg = layout.createsequentialgroup(); hg.addcomponent(c1).addcomponent(c2).addcomponent(c3); layout.setverticalgroup(vg); 2006 JavaOne SM Conference Session TS-4916 39

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 40

Internationalization How to make the GUI localizable Allow translation without rebuilding the GUI No hard coded strings Stored in.properties file Accessed via ResourceBundle All visible text should be internationalized Text on labels, buttons, tabs, titled borders, etc. Window titles Tool tips Mnemonics Accessibility descriptions 2006 JavaOne SM Conference Session TS-4916 41

DEMO Internationalization 2006 JavaOne SM Conference Session TS-4916 42

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 43

Custom Components Using custom components in GUI builder Only requirement: must be JavaBeans architecture compliant Can be installed to palette via Palette Manager From an external JAR file (library) From a NetBeans IDE project If in a project, the component can be copied or dragged from the project explorer directly 2006 JavaOne SM Conference Session TS-4916 44

Custom Components Developing your own component JavaBeans architecture requirements: Public non-abstract class Public no-arg constructor Good practice is to only expose properties that makes sense (via BeanInfo) Return superclass BeanInfo as additional BeanInfo Use Java-Bean tag in the JAR file s manifest Define icon for the component (BeanInfo) 2006 JavaOne SM Conference Session TS-4916 45

Example: Java-Bean Tag in manifest.mf Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build Name: com/me/beans/mycomponent.class Java-Bean: True Go to Files view Open manifest.mf file under project root Enter the last two lines as marked above, separated by an empty line 2006 JavaOne SM Conference Session TS-4916 46

Example: Component s Icon package com.me.beans; import java.beans.simplebeaninfo; import java.awt.image; /** * Simple BeanInfo implementation for MyComponent. * Only provides an icon (the rest is omitted). */ public class MyComponentBeanInfo extends SimpleBeanInfo { public Image geticon(int iconkind) { return loadimage("/com/me/beans/cool_icon.gif"); } } 2006 JavaOne SM Conference Session TS-4916 47

Custom Components Troubleshooting, common errors Class loading error Check the required JAR file (external component) Note: a library needs to be defined for multiple JARs Check the class is compiled (component from a project) Instantiation error check the sources: Whether the component is a bean What it does in constructor Look at the exception stack trace See NetBeans IDE FAQs for complete guide 2006 JavaOne SM Conference Session TS-4916 48

DEMO Using Custom Components 2006 JavaOne SM Conference Session TS-4916 49

Agenda NetBeans GUI Builder Introduction Cross Platform UI How to Design Layout Internationalization Using Custom Components Managing Generated Code 2006 JavaOne SM Conference Session TS-4916 50

Source Code Generated code vs. user code Standard Java technology code is the only output Generated code is protected from changes initcomponents() method Field variables for components Event handlers (headers) Can write any code outside the protected area To do more initialization/customization To implement additional logic (e.g., event handlers) To change components dynamically 2006 JavaOne SM Conference Session TS-4916 51

Source Code Customizing generated code See Code tab in the property sheet Generated code can be configured freely Local variables vs member fields, modifiers, way of dispatching events Custom code can be inserted almost anywhere Custom code for property values Custom code for creating components Pre-init and post-init code for components/properties Synthetic properties 2006 JavaOne SM Conference Session TS-4916 52

Source Code Examples of using custom code Setting up a complex property Special way of initialization (not via properties) For example binding to a dynamic content Special way of constructing a component For example JFormattedTextField Iterating over many components, for example: Creating a collection of components Setting some property to all components 2006 JavaOne SM Conference Session TS-4916 53

DEMO Customizing Generated Code 2006 JavaOne SM Conference Session TS-4916 54

Summary NetBeans GUI Builder is designed to help you create professional UIs The GUI Builder honors platform independence and internationalization Standard Java technology code is produced that can be used anywhere You can use third-party components and develop own custom components 2006 JavaOne SM Conference Session TS-4916 55

For More Information http://form.netbeans.org/javaone http://www.netbeans.org/kb/50/quickstart-gui.html http://www.netbeans.org/kb/faqs/#gui_editor_matisse http://swing-layout.dev.java.net Related Sessions TS-1594 Best Practices: Data Binding TS-3399 A Simple Framework for Desktop Applications Blogs http://weblogs.java.net/blog/zixle http://weblogs.java.net/blog/tpavek 2006 JavaOne SM Conference Session TS-4916 56

Q&A 2006 JavaOne SM Conference Session TS-4916 57

Creating Professional Swing UIs Using the NetBeans GUI Builder Tomas Pavek, Jan Stola, Scott Violet Sun Microsystems http://www.netbeans.org http://swinglabs.dev.java.net TS-4916 2006 JavaOne SM Conference Session TS-4916