O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A GridBagLayout Example

Theory is good, but we need to put some code behind these abstract concepts. The following example, from GridBag.py, takes us step by step through the layout of components with GridBagLayout. At first we'll use only buttons; then we'll graduate to other components such as text fields and labels. To start, import the classes needed.

>>> from javax.swing import JButton, JTextField, JFrame, JButton, JPanel, JLabel
>>> from java.awt import GridBagLayout, GridBagConstraints

Constraints

Define a helper function for creating GridBagConstraints. If you're following along in the interactive interpreter, enter from GridBag import makeConstraint.

 def makeConstraint() gridx=0, gridy=0, # Holds the x, y cell location in the grid ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required