Associate JLabel component with a JTextField : TextField « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing JFC » TextFieldScreenshots 
Associate JLabel component with a JTextField
    
 
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Main extends JFrame {
  public Main() throws HeadlessException {
    setSize(400200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    JLabel usernameLabel = new JLabel("Username: ");
    JLabel passwordLabel = new JLabel("Password: ");
    JTextField usernameField = new JTextField(20);
    JPasswordField passwordField = new JPasswordField(20);

    usernameLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    usernameLabel.setLabelFor(usernameField);
    passwordLabel.setDisplayedMnemonic(KeyEvent.VK_P);
    passwordLabel.setLabelFor(passwordField);

    getContentPane().add(usernameLabel);
    getContentPane().add(usernameField);
    getContentPane().add(passwordLabel);
    getContentPane().add(passwordField);
  }

  public static void main(String[] args) {
    new Main().setVisible(true);
  }
}
 

   
    
    
    
  
Related examples in the same category
1. Make a Text Field two columns wide
2. Water mark text field
3. Auto complete TextField
4. Text fields and Java eventsText fields and Java events
5. JTextField Alignment SampleJTextField Alignment Sample
6. Create the textfieldCreate the textfield
7. FieldEdit - an Applet to validate data as it's being entered
8. TextField with only Integer value
9. File Name Bean
10. Textfield only accepts numbersTextfield only accepts numbers
11. Overwritable TextFieldOverwritable TextField
12. Numeric TextFieldNumeric TextField
13. Passive TextField 1Passive TextField 1
14. Passive TextField 2Passive TextField 2
15. Text Accelerator ExampleText Accelerator Example
16. TextField Look Ahead ExampleTextField Look Ahead Example
17. Passive TextField 3Passive TextField 3
18. Non Wrapping(Wrap) TextPaneNon Wrapping(Wrap) TextPane
19. EditabilityExampleEditabilityExample
20. Bounded TextFieldBounded TextField
21. TextField ElementsTextField Elements
22. TextFieldViews 2TextFieldViews 2
23. TextField with ConstaintsTextField with Constaints
24. JTextField Sample 2JTextField Sample 2
25. JTextField Verifier SampleJTextField Verifier Sample
26. A simple label for field form panelA simple label for field form panel
27. A hack to make a JTextField really 2 columns wideA hack to make a JTextField really 2 columns wide
28. Limit JTextField input to a maximum length
29. Make sure that my JTextField has the focus when a JFrame is created
30. Make the ENTER key act like the TAB key
31. Setting up a textfield and modifying its horizontal alignment at runtimeSetting up a textfield and modifying its horizontal alignment at runtime
32. Aligning the Text in a JTextField Component
33. Based on JTextField content, enable or disable a JButton
34. Cut, paste, and copy in a JTextField under program control.
35. Add key listener event handler to JTextField
36. Right justified JTextfield content
37. Set the focus on a particular JTextField
38. Right justified JTextField contents
39. Validate a value on the lostFocus event
40. Modify horizontal alignment of text field at runtime
41. Make sure that my Text field has the focus when a JFrame is created
42. Firing Item Events
43. extends JTextField to create integer JTextField
44. JTextField Max Length
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.