# Value CENTER is not a member of object javax.swing.JLabel

**URL:** <https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061>\
**Category:** Question\
**Created:** [January 25, 2021, 2:54pm UTC](https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061 "2021-01-25T14:54:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmf](https://users.scala-lang.org/user_avatar/users.scala-lang.org/hmf/32/426_2.png) [@hmf](https://users.scala-lang.org/u/hmf)\
**Post date:** [January 25, 2021, 2:54pm UTC](https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061/1 "2021-01-25T14:54:12Z")

</div>

I am translating code from Java to Scala and came across this:

```java
JLabel l = new JLabel(label, JLabel.CENTER);

```

so I tried:

```auto
    val l = new JLabel(trueLabel, JLabel.CENTER)

```

and the compiler tells me that `CENTER` is not a member. But looking at the source I have:

```auto
public class JLabel extends JComponent implements SwingConstants, Accessible
{
  ...
}

```

and

```auto
public interface SwingConstants {

        /**
         * The central position in an area. Used for
         * both compass-direction constants (NORTH, etc.)
         * and box-orientation constants (TOP, etc.).
         */
        public static final int CENTER = 0;

```

Do I have to do anything from the Scala side to access this member?  
I am using Scala 3 (Dotty)

TIA

---

<div class="post-metadata">

**Author:** ![sangamon](https://users.scala-lang.org/user_avatar/users.scala-lang.org/sangamon/32/68_2.png) [@sangamon](https://users.scala-lang.org/u/sangamon)\
**Post date:** [January 25, 2021, 3:03pm UTC](https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061/2 "2021-01-25T15:03:32Z")

</div>

`SwingConstants.CENTER` …?

---

<div class="post-metadata">

**Author:** ![hmf](https://users.scala-lang.org/user_avatar/users.scala-lang.org/hmf/32/426_2.png) [@hmf](https://users.scala-lang.org/u/hmf)\
**Post date:** [January 25, 2021, 3:21pm UTC](https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061/4 "2021-01-25T15:21:30Z")

</div>

Messed up a direct reply. Trying again…

I am using that, however I am assuming the `implements` should work. Note that if it does not work, this means we have to manually _hunt down_ the definitions. This does not seem to be practical. Maybe I am missing something obvious?

Thank you.

---

<div class="post-metadata">

**Author:** ![sangamon](https://users.scala-lang.org/user_avatar/users.scala-lang.org/sangamon/32/68_2.png) [@sangamon](https://users.scala-lang.org/u/sangamon)\
**Post date:** [January 25, 2021, 3:44pm UTC](https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061/5 "2021-01-25T15:44:23Z")

</div>

In Java, interface fields are static, so they most naturally map to members in the companion object of a trait in Scala. While you can access static members via an object reference in Java, the (unmaintained?) [code conventions](https://www.oracle.com/technetwork/java/codeconventions-150003.pdf) state: “Avoid using an object to access a class (static) variable or method. Use a class name instead.” (§10.2)

So while I don’t know the actual mechanics at play in Java interop, I’m not terribly surprised that inheritance doesn’t seem to apply to Java interface fields when viewed from the Scala side.

---

<div class="post-metadata">

**Author:** ![curoli](https://users.scala-lang.org/user_avatar/users.scala-lang.org/curoli/32/1753_2.png) [@curoli](https://users.scala-lang.org/u/curoli)\
**Post date:** [January 25, 2021, 3:49pm UTC](https://users.scala-lang.org/t/value-center-is-not-a-member-of-object-javax-swing-jlabel/7061/6 "2021-01-25T15:49:12Z")

</div>

In Java, static members like `CENTER` are inherited just like non-static members.

When referring from Scala to a static member from Java it is understood to be a member of the companion object and is not inherited.

So, yes, you need to find out where it is actually defined.
