Hey,
This patch fixes a couple of bugs in javax.swing.JLabel's constructors.
The first is that null is permitted as the text and the horizontal
alignment must be one of CENTER, LEFT, RIGHT, LEADING or TRAILING. This
patch now passes a couple of failing Harmony's tests. I have also
written and commited mauve tests.
Cheers,
Tania
2006-11-09 Tania Bento <[EMAIL PROTECTED]>
* javax/swing/JLabel.java
(JLabel(Icon)): Changed documentation; Changed text to null.
(JLabel(Icon,int)): Likewise.
(JLabel(text)): Changed documenation.
(JLabel(text,int)): Likewise.
(JLabel(text,Icon,int)): Changed documentation; Throw
IllegalArgumentException if int is not one of LEFT, RIGHT,
CENTER, LEADING or TRAILING.
Index: javax/swing/JLabel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JLabel.java,v
retrieving revision 1.42
diff -u -r1.42 JLabel.java
--- javax/swing/JLabel.java 16 Oct 2006 11:48:46 -0000 1.42
+++ javax/swing/JLabel.java 9 Nov 2006 19:16:13 -0000
@@ -431,11 +431,11 @@
* Creates a new vertically and horizontally centered
* JLabel object with no text and the given icon.
*
- * @param image The icon to use with the label.
+ * @param image The icon to use with the label, <code>null</code> permitted.
*/
public JLabel(Icon image)
{
- this("", image, CENTER);
+ this(null, image, CENTER);
}
/**
@@ -443,19 +443,21 @@
* given icon and horizontal alignment. By default, the text is TRAILING
* the image.
*
- * @param image The icon to use with the label.
- * @param horizontalAlignment The horizontal alignment of the label.
+ * @param image The icon to use with the label, <code>null</code> premitted.
+ * @param horizontalAlignment The horizontal alignment of the label, must be
+ * either <code>CENTER</code>, <code>LEFT</code>, <code>RIGHT</code>,
+ * <code>LEADING</code> or <code>TRAILING</code>.
*/
public JLabel(Icon image, int horizontalAlignment)
{
- this("", image, horizontalAlignment);
+ this(null, image, horizontalAlignment);
}
/**
* Creates a new horizontally leading and vertically centered JLabel
* object with no icon and the given text.
*
- * @param text The text to use with the label.
+ * @param text The text to use with the label, <code>null</code> permitted.
*/
public JLabel(String text)
{
@@ -466,8 +468,10 @@
* Creates a new vertically centered JLabel object with no icon and the
* given text and horizontal alignment.
*
- * @param text The text to use with the label.
- * @param horizontalAlignment The horizontal alignment of the label.
+ * @param text The text to use with the label, <code>null</code> permitted.
+ * @param horizontalAlignment The horizontal alignment of the label, must be
+ * either <code>CENTER</code>, <code>LEFT</code>, <code>RIGHT</code>,
+ * <code>LEADING</code> or <code>TRAILING</code>.
*/
public JLabel(String text, int horizontalAlignment)
{
@@ -478,12 +482,21 @@
* Creates a new vertically centered JLabel object with the given text,
* icon, and horizontal alignment.
*
- * @param text The text to use with the label.
- * @param icon The icon to use with the label.
- * @param horizontalAlignment The horizontal alignment of the label.
+ * @param text The text to use with the label, <code>null</code> permitted.
+ * @param icon The icon to use with the label, <code>null</code> premitted.
+ * @param horizontalAlignment The horizontal alignment of the label, must be
+ * either <code>CENTER</code>, <code>LEFT</code>, <code>RIGHT</code>,
+ * <code>LEADING</code> or <code>TRAILING</code>.
*/
public JLabel(String text, Icon icon, int horizontalAlignment)
{
+ if (horizontalAlignment != SwingConstants.LEFT
+ && horizontalAlignment != SwingConstants.RIGHT
+ && horizontalAlignment != SwingConstants.CENTER
+ && horizontalAlignment != SwingConstants.LEADING
+ && horizontalAlignment != SwingConstants.TRAILING)
+ throw new IllegalArgumentException();
+
this.text = text;
this.icon = icon;
this.horizontalAlignment = horizontalAlignment;