Note that there are some explanatory texts on larger screens.

plurals
  1. POIs the ordering of static members sensitive in Swing?
    primarykey
    data
    text
    <p>I have this class, let's say, <code>Foo</code>. It <code>extends JFrame</code> and is a singleton. That being said, it has two <strong>static fields</strong>: 1) an instance of <code>Foo</code> and 2) a <code>Color</code>.</p> <p><strong>Here's a code snippet of <code>Foo</code>:</strong> </p> <pre><code>public class Foo extends JFrame{ private static final Color FOO_RED = new Color(155, 64, 69); private static final Foo INSTANCE = new Foo(); private Foo(){ //do stuff } public static Foo getInstance(){ return INSTANCE; } } </code></pre> <p>I also have another class, let's say, <code>Launcher</code>. This is the <strong>main class</strong> that is responsible for launching the application. It's a simple class in that its only job is to delegate the task of constructing <code>Foo</code> to the <code>EDT</code>.</p> <p><strong>Here's a code snippet of <code>Launcher</code>:</strong></p> <pre><code>public class Launcher{ public static void main(String[] args){ SwingUtilities.invokeLater((new Runnable(){ @Override public void run() { Foo.getInstance(); } })); } } </code></pre> <p>Now, this all works just fine. <strong>But</strong>, when I switch the ordering of <code>Foo</code>'s fields (<strong>See below</strong>), the components that use <code>FOO_RED</code> are no longer painted this color. </p> <pre><code>public class Foo extends JFrame{ private static final Foo INSTANCE = new Foo(); //declared before Color private static final Color FOO_RED = new Color(155, 64, 69); private Foo(){ //do stuff } public static Foo getInstance(){ return INSTANCE; } } </code></pre> <p>So, this begs the question, does the ordering of <strong>static fields</strong> matter when it comes to <code>Swing</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload