SWING - GROUPLAYOUT CLASS

Similar documents
AWT CHECKBOX CLASS. Creates a check box with the specified label and sets the specified state.

AWT CHOICE CLASS. Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the menu.

AWT SCROLLBAR CLASS. Scrollbar control represents a scroll bar component in order to enable user to select from range of values.

AWT DIALOG CLASS. Dialog control represents a top-level window with a title and a border used to take some form of input from the user.

AWT TEXTFIELD CLASS. Constructs a new empty text field with the specified number of columns.

AWT LIST CLASS. The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items.

AWT WINDOW CLASS. The class Window is a top level window with no border and no menubar. It uses BorderLayout as default layout manager.

AWT MENUBAR CLASS. Introduction. Class declaration. Class constructors. Class methods

Laborator 2 Aplicatii Java

AWT COLOR CLASS. Introduction. Class declaration. Field

AWT QUADCURVE2D CLASS

AWT GRAPHICS CLASS. Introduction. Class declaration. Class constructors. Class methods

CS 251 Intermediate Programming GUIs: Components and Layout

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Dr. Hikmat A. M. AbdelJaber

Window Interfaces Using Swing Objects

Basicsof. JavaGUI and SWING

Laying Out Components. What is Widget Layout?

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

First Name: AITI 2004: Exam 2 July 19, 2004

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Containers and Components

Swing from A to Z Some Simple Components. Preface

First Name: AITI 2004: Exam 2 July 19, 2004

Introduction to the JAVA UI classes Advanced HCI IAT351

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Programming Mobile Devices J2SE GUI

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Starting Out with Java: From Control Structures Through Objects Sixth Edition

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Window Interfaces Using Swing Objects

1005ICT Object Oriented Programming Lecture Notes

CS Exam 1 Review Suggestions

Top-Level Containers

Swing from A to Z Using Focus in Swing, Part 2. Preface

JAVA NOTES GRAPHICAL USER INTERFACES

Graphical User Interface (GUI)

Final Examination Semester 2 / Year 2010

Graphical User Interface (GUI)

Graphics User Defined Forms, Part I

Programming Languages and Techniques (CIS120e)

Part 3: Graphical User Interface (GUI) & Java Applets

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Example 3-1. Password Validation

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Java, Swing, and Eclipse: The Calculator Lab.

Graphic User Interfaces. - GUI concepts - Swing - AWT

2IS45 Programming

SINGLE EVENT HANDLING

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Swing/GUI Cheat Sheet

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

AP CS Unit 11: Graphics and Events

JFrame & JLabel. By Iqtidar Ali

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

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

MIT AITI Swing Event Model Lecture 17

We are on the GUI fast track path

Lecture 5: Java Graphics

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Systems Programming Graphical User Interfaces

DM503 Programming B. Peter Schneider-Kamp.

1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the

Part I: Learn Common Graphics Components

Lecture 9. Lecture

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

More Swing. CS180 Recitation 12/(04,05)/08

CS 180 Final Exam Review 12/(11, 12)/08

Creating Professional Swing UIs Using the NetBeans GUI Builder

Swing - JButton. Adding buttons to the main window

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

GUI Forms and Events, Part II

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

Packages: Putting Classes Together

CS11 Java. Fall Lecture 3

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

University of Cape Town Department of Computer Science Computer Science CSC1017F

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Layout. Dynamic layout Layout design pattern Layout strategies

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Layout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

JFrame In Swing, a JFrame is similar to a window in your operating system

Layout. Dynamic layout, Swing and general layout strategies

Transcription:

SWING - GROUPLAYOUT CLASS http://www.tutorialspoint.com/swing/swing_grouplayout.htm Copyright tutorialspoint.com Introduction The class GroupLayout hierarchically groups components in order to position them in a Container. Class declaration Following is the declaration for javax.swing.grouplayout class: public class GroupLayout extends Object implements LayoutManager2 Field Following are the fields for javax.swing.grouplayout class: static int DEFAULT_SIZE -- Indicates the size from the component or gap should be used for a particular range value. static int PREFERRED_SIZE -- Indicates the preferred size from the component or gap should be used for a particular range value. Class constructors S.N. Constructor & Description 1 GroupLayoutContainerhost Creates a GroupLayout for the specified Container. Class methods S.N. Method & Description 1 void addlayoutcomponentcomponentcomponent, Objectconstraints Notification that a Component has been added to the parent container. 2 void addlayoutcomponentstringname, Componentcomponent Notification that a Component has been added to the parent container. 3 GroupLayout.ParallelGroup createbaselinegroup booleanresizable, booleananchorbaselinetotop Creates and returns a ParallelGroup that aligns it's elements along the baseline. 4 GroupLayout.ParallelGroup createparallelgroup Creates and returns a ParallelGroup with an alignment of Alignment.LEADING.

5 GroupLayout.ParallelGroup createparallelgroupgrouplayout. Alignmentalignment Creates and returns a ParallelGroup with the specified alignment. 6 GroupLayout.ParallelGroup createparallelgroup GroupLayout. Alignmentalignment, booleanresizable Creates and returns a ParallelGroup with the specified alignment and resize behavior. 7 GroupLayout.SequentialGroup createsequentialgroup Creates and returns a SequentialGroup. 8 boolean getautocreatecontainergaps Returns true if gaps between the container and components that border the container are automatically created. 9 boolean getautocreategaps Returns true if gaps between components are automatically created. 10 boolean gethonorsvisibility Returns whether component visiblity is considered when sizing and positioning components. 11 float getlayoutalignmentxcontainerparent Returns the alignment along the x axis. 12 float getlayoutalignmentycontainerparent Returns the alignment along the y axis. 13 LayoutStyle getlayoutstyle Returns the LayoutStyle used for calculating the preferred gap between components. 14 void invalidatelayoutcontainerparent Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. 15 void layoutcontainercontainerparent Lays out the specified container. 16 void linksizecomponent... components Forces the specified components to have the same size regardless of their preferred, minimum or maximum sizes. 17 void linksizeintaxis, Component... components Forces the specified components to have the same size along the specified axis regardless of their preferred, minimum or maximum sizes.

18 Dimension maximumlayoutsizecontainerparent Returns the maximum size for the specified container. 19 Dimension minimumlayoutsizecontainerparent Returns the minimum size for the specified container. 20 Dimension preferredlayoutsizecontainerparent Returns the preferred size for the specified container. 21 void removelayoutcomponentcomponentcomponent Notification that a Component has been removed from the parent container. 22 void replacecomponentexistingcomponent, ComponentnewComponent Replaces an existing component with a new one. 23 void setautocreatecontainergapsbooleanautocreatecontainerpadding Sets whether a gap between the container and components that touch the border of the container should automatically be created. 24 void setautocreategapsbooleanautocreatepadding Sets whether a gap between components should automatically be created. 25 void sethonorsvisibilitybooleanhonorsvisibility Sets whether component visiblity is considered when sizing and positioning components. 26 void sethonorsvisibilitycomponentcomponent, BooleanhonorsVisibility Sets whether the component's visiblity is considered for sizing and positioning. 27 void sethorizontalgroupgrouplayout. Groupgroup Sets the Group that positions and sizes components along the horizontal axis. 28 void setlayoutstylelayoutstylelayoutstyle Sets the LayoutStyle used to calculate the preferred gaps between components. 29 void setverticalgroupgrouplayout. Groupgroup Sets the Group that positions and sizes components along the vertical axis. 30 String tostring Returns a string representation of this GroupLayout. Methods inherited

This class inherits methods from the following classes: java.lang.object GroupLayout Example Create the following java program using any editor of your choice in say D:/ > SWING > com > tutorialspoint > gui > SwingLayoutDemo.java package com.tutorialspoint.gui; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingLayoutDemo { private JFrame mainframe; private JLabel headerlabel; private JLabel statuslabel; private JPanel controlpanel; private JLabel msglabel; public SwingLayoutDemo(){ preparegui(); public static void main(string[] args){ SwingLayoutDemo swinglayoutdemo = new SwingLayoutDemo(); swinglayoutdemo.showgrouplayoutdemo(); private void preparegui(){ mainframe = new JFrame("Java SWING Examples"); mainframe.setsize(400,400); mainframe.setlayout(new GridLayout(3, 1)); headerlabel = new JLabel("",JLabel.CENTER ); statuslabel = new JLabel("",JLabel.CENTER); statuslabel.setsize(350,100); mainframe.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent windowevent){ System.exit(0); ); controlpanel = new JPanel(); controlpanel.setlayout(new FlowLayout()); mainframe.add(headerlabel); mainframe.add(controlpanel); mainframe.add(statuslabel); mainframe.setvisible(true); private void showgrouplayoutdemo(){ headerlabel.settext("layout in action: GroupLayout"); JPanel panel = new JPanel(); // panel.setbackground(color.darkgray); panel.setsize(200,200); GroupLayout layout = new GroupLayout(panel); layout.setautocreategaps(true); layout.setautocreatecontainergaps(true); JButton btn1 = new JButton("Button 1"); JButton btn2 = new JButton("Button 2"); JButton btn3 = new JButton("Button 3"); layout.sethorizontalgroup(layout.createsequentialgroup()

);.addcomponent(btn1).addgroup(layout.createsequentialgroup().addgroup(layout.createparallelgroup( GroupLayout.Alignment.LEADING).addComponent(btn2).addComponent(btn3) ) ) layout.setverticalgroup(layout.createsequentialgroup().addcomponent(btn1).addcomponent(btn2).addcomponent(btn3) ); panel.setlayout(layout); controlpanel.add(panel); mainframe.setvisible(true); Compile the program using command prompt. Go to D:/ > SWING and type the following command. D:\SWING>javac com\tutorialspoint\gui\swinglayoutdemo.java If no error comes that means compilation is successful. Run the program using following command. D:\SWING>java com.tutorialspoint.gui.swinglayoutdemo Verify the following output Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js