JTextField

JTextField allows you to edit text in text fields. It's pretty basic and can be explained with a simple example. Import JTextField and JFrame from the javax.swing package.

>>> from javax.swing import JTextField

Create a frame and a text field, and add it to the frame. We'll use this text field to demonstrate how to set and read text. Create the frame.

>>> frame = JFrame()

Create the TextField instance.

>>> textField = JTextField(20)

Add the instance to the center of the frame.

>>> from java.awt import BorderLayout
>>> frame.add(textField, BorderLayout.CENTER)

Default Layout Manager

The default layout manager for the frame is BorderLayout, which essentially allows you to add components to a frame's north, south, east, and west ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.