Java™ 7: A Beginner's Tutorial (Third Edition) by Budi Kurniawan

Java™ 7: A Beginner's Tutorial (Third Edition) by Budi Kurniawan

Author:Budi Kurniawan
Language: eng
Format: epub, azw3
ISBN: 9780980839616
Publisher: Budi Kurniawan


Figure 16.2: A JFrame that uses a BorderLayout (left) and the same JFrame resized (right)

Note that the JTextField and the JButton are placed in the west and east regions of the JFrame. If you resize the JFrame, the components will maintain their positions. The size of each component adjusts accordingly, and setting the size of the components (by using setSize) does not have effect. It is clear the BorderLayout has the final say with regard to the components’ sizes and positions.

Listing 16.2 shows another example of BorderLayout.

Listing 16.2: Another example of BorderLayout

package app16; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class BorderLayoutTest2 extends JFrame { private static void constructGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("BorderLayout Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); JLabel label1 = new JLabel("Registration Form"); label1.setHorizontalAlignment(JLabel.CENTER); frame.add(label1, BorderLayout.NORTH); JLabel label2 = new JLabel("Name:") frame.add(label2, BorderLayout.WEST); JTextField textField = new JTextField("<your name>"); frame.add(textField, BorderLayout.CENTER); JButton button1 = new JButton("Register"); frame.add(button1, BorderLayout.EAST); JButton button2 = new JButton("Clear Form"); frame.add(button2, BorderLayout.SOUTH); frame.setSize(300, 150); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { constructGUI(); } }); } }

Figure 16.3 shows the result of running the code in Listing 16.2.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Learning Java by Patrick Niemeyer & Daniel Leuck(2881)
Java For Testers: Learn Java fundamentals fast by Alan Richardson(1244)
Learn C Programming by Jeff Szuhay(1241)
Hands-On Design Patterns with Java by Dr. Edward Lavieri;(1190)
600 Basic Japanese Verbs by Hiro Japanese Center(973)
MATLAB - Programming with MATLAB for Beginners - A Practical Introduction to Programming and Problem Solving (Matlab for Engineers, MATLAB for Scientists, Matlab Programming for Dummies) by Learning UpSkill(874)
Practice Makes Perfect: Basic Spanish by Dorothy Richmond(684)
Basic Mathematics: An Introduction: Teach Yourself by Graham Alan(621)
This Lullaby(601)
Book 2 by Unknown(599)
Java™ 7: A Beginner's Tutorial (Third Edition) by Budi Kurniawan(572)
Learning Java by Marc Loy(515)
The First 100 Chinese Characters by Alison Matthews & Laurence Matthews(506)
0-In the Beginning by Peter David(504)
Quick And Easy Vector Graphics: Learn the 5 basic skills that will have you creating icons, logos, illustrations and UI in minutes (Graphic Design for Beginners Book 1) by Tsagaris Antonis(494)
Computer Programming: PYTHON: A step-by-step giude to learn the basic concepts of Python Programming Language with practical exercises by Tony Chan(460)
Learn Arduino Programming using 37 sensors for beginners : Practical way to learn Arduino for the year 2017 by Jennifer Williams(452)
Frank and I by Anonymous(438)
Learning Perl by Randal L. Schwartz & Tom Phoenix & brian d foy(430)
Beginning Microsoft SQL Server 2008 Programming by Robert Vieira(427)