JDK-4172932 : BorderLayout provides no way to get the constraint for each child
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0,1.3.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 1998-09-11
  • Updated: 2017-05-16
  • Resolved: 2003-08-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Description

Name: clC74495			Date: 09/11/98


We are building a SwingSet IDE. Among other things
the visual editor must allow a user to edit the
LayoutManager that is attached to a JPanel.
The BorderLayout's API provides no way to find the
constraint associated with each child ("North",
"South", "East", etc.).

GridBagLayout already has such a thing:
(getConstaints).

Without this ability the BorderLayout is clumsy and
confusing when used in conjunction with an IDE
supporting a visual editor, since if the user
wants to edit a Component's contraint we
can't display the current value.

Adding a new methods called getConstraint(Component)
which returned a String would solve this problem.
(Review ID: 38184)
======================================================================

Name: krC82822			Date: 07/31/2001


java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

It's currently not possible to tell how a given component is constrained
in a BorderLayout, or what component is at a specific constraint.  There
are cases where this information is crucial. For example, restoring the
current location of a tool palette in a BorderLayout requires being able
to tell that the user dragged the palette to another position, and then
to save the new constraint.  This information is locked up in the layout,
and there doesn't seem to be a practical way to recover it.
(Review ID: 127797)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b16
14-06-2004

EVALUATION Sounds reasonable. michael.martak@Eng 2000-01-03 Adding three methods to BorderLayout, one to get the constraints for a component, and two slightly different ways to get the component for a given constraint (taking component orientation into account or not). ###@###.### 2003-07-17
17-07-2003

SUGGESTED FIX /** * Get the component that was added using the given constraint * * @param constraints The desired constraint, * one of NORTH, SOUTH, WEST, EAST, CENTER, * PAGE_START, PAGE_END, LINE_START, LINE_END. * @return the component at the given location, or </code>null</code> if * the location is empty. * @see @addLayoutComponent(java.awt.Component, java.lang.Object) * @exception IllegalArgumentException if the constraint object is * not one of the nine specified constants. */ public Component getLayoutComponent(Object constraints) { if (CENTER.equals(constraints)) { return center; } else if (NORTH.equals(constraints)) { return north; } else if (SOUTH.equals(constraints)) { return south; } else if (WEST.equals(constraints)) { return west; } else if (EAST.equals(constraints)) { return east; } else if (PAGE_START.equals(constraints)) { return firstLine; } else if (PAGE_END.equals(constraints)) { return lastLine; } else if (LINE_START.equals(constraints)) { return firstItem; } else if (LINE_END.equals(constraints)) { return lastItem; } else { throw new IllegalArgumentException("cannot get component: unknown constraint: " + constraints); } } /** * Get the component that corresponds to the given constraint location * based on the target Container's component orientation. * * @param constraints The desired absolute position, * one of NORTH, SOUTH, EAST, WEST, CENTER. * @param target The <code>Container</code> using this <code>BorderLayout</code> * @return the component at the given location, or </code>null</code> if * the location is empty. * @see @addLayoutComponent(java.awt.Component, java.lang.Object) * @exception IllegalArgumentException if the constraint object is * not one of the five specified constants. */ public Component getLayoutComponent(Container target, Object constraints) { boolean ltr = target.getComponentOrientation().isLeftToRight(); Component result = null; if (NORTH.equals(constraints)) { result = (firstLine != null) ? firstLine : north; } else if (SOUTH.equals(constraints)) { result = (lastLine != null) ? lastLine : south; } else if (WEST.equals(constraints)) { result = ltr ? firstItem : lastItem; if (result == null) { result = west; } } else if (EAST.equals(constraints)) { result = ltr ? lastItem : firstItem; if (result == null) { result = east; } } else if (CENTER.equals(constraints)) { result = center; } else { throw new IllegalArgumentException("cannot get component: invalid constraint: " + constraints); } return result; } /** * Get the constraints for the specified component. * * @param comp the component to be queried * @return the component at the given location, or </code>null</code> if * the location is empty. * @see @addLayoutComponent(java.awt.Component, java.lang.Object) * @return the constraint for the specified component, * or null if component is not present in this layout. */ public Object getConstraints(Component comp) { if (comp == center) { return CENTER; } else if (comp == north) { return NORTH; } else if (comp == south) { return SOUTH; } else if (comp == west) { return WEST; } else if (comp == east) { return EAST; } else if (comp == firstLine) { return PAGE_START; } else if (comp == lastLine) { return PAGE_END; } else if (comp == firstItem) { return LINE_START; } else if (comp == lastItem) { return LINE_END; } return null; } ###@###.### 2003-07-17
17-07-2003