Setting Component Size and Resizability


To set a component's size, grab one of its corners or edges and drag it to the desired size. Many components automatically expand in size to accommodate any text and icons that are inserted into them.

Another important function is setting components to be the same size. For example, a form could have the standard OK, Cancel, and Help buttons. By default, each button would only be as wide as its containing text. The form looks much better, however, when you set all three buttons to be the same width.

To set multiple components to be the same size:

  1. Shift-click the components to select them.

  2. Right-click any of the selected components and choose Same Size | Same Width/Same Height.

To set a component to automatically resize as its container resizes, do one of the following:

  • Resize the component to snap to the edges of its container.

  • Use the and buttons in the Form Designer toolbar.

Figure 6-5 shows all of these concepts at work together. The two JLists must have the same width and automatically resize both vertically and horizontally when you resize the dialog. To achieve this state, do the following:

  1. Insert two JLists, each snapped to the left edge of the JLabel above them.

  2. Expand the JList on the left to snap to the side of the JList on the right.

  3. Expand the JList on the right to snap to the edge of the JFrame.

  4. Select both JLists by shift-clicking them.

  5. Right-click either of the JLists and choose Same Size | Same Width.

  6. Click the and buttons to set the resizing behavior.

Figure 6-5. Two JList components set to be the same size and resize automatically


Note that you cannot set the resizing behavior for components that are set to be the same size. In the example in Figure 6-5, you set the forms to be the same initial size when you used the Same Width command. When you set the resizing behavior, however, you broke the Same Width link between the two lists. Because they are both set to resize both vertically and horizontally, they will retain their same size automatically.




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net