Page 731 - Introduction to Programming with Java: A Problem Solving Approach
P. 731

                Assume you’ve implemented a program that prompts the user to enter his/her name and prints a person- alized greeting after the user presses enter. We’ll show you a sample session that starts with a wide window and a short name. Here’s what the program displays after the user types Tom:
And here’s what the program displays after the user presses enter:
If the user enters a longer name, like Fidelis Kiungua, the greeting label can’t fit on the first line, so it wraps to the next line:
          Apago PDF Enhancer
If the user manually resizes the window to make it narrower, the text box can no longer fit on the first line, so it wraps to the next line:
Alignment
By default, the FlowLayout manager positions its components using center alignment. For example, in the above window, note how the “What’s your name” label is centered between the left and right borders. If you’d like to change the FlowLayout manager’s alignment, insert one of the FlowLayout alignment constants (FlowLayout.LEFT, FlowLayout.CENTER, FlowLayout.RIGHT) in the FlowLayout constructor call. For example, here’s how to specify left alignment:
setLayout(new FlowLayout(FlowLayout.LEFT));
17.3 FlowLayout Manager 697
    Here’s what our Greeting program displays when left alignment is used:

























































































   729   730   731   732   733