1

For example: can this be used in a class MyPane?

public class MyPane extends JRootPane{
    public static JCheckBox Debug= new JCheckBox("Debug");
....
}

Will Swing have problem? Should we always put these assignment in invokeLater? Thanks.

Hai Bi
  • 1,173
  • 1
  • 11
  • 21
  • 3
    Why would you want to use static anything in a Swing GUI? What would be your motivation for wanting to do this? – Hovercraft Full Of Eels Jan 16 '13 at 00:46
  • 1
    Swing won't have a problem with it, every body else might ... – MadProgrammer Jan 16 '13 at 00:52
  • 3
    @Mad: I don't agree. Swing in fact might have a problem with it, but I don't think that it can be 100% predicted if it will. It is always safest to create JComponents on the EDT. – Hovercraft Full Of Eels Jan 16 '13 at 01:07
  • @HovercraftFullOfEels Oh, nice point! Hadn't thought about the creation order of objects! – MadProgrammer Jan 16 '13 at 01:13
  • @HovercraftFullOfEels: Basically I am trying to use a singleton. I saw other people's code liek thsi too. Fortunately, this is the only problem now. I am going to put all these to singleton style and use invokeLater(). – Hai Bi Jan 16 '13 at 02:29
  • Don't use a singleton! (Regards class initialisation, it's probably going to be initialised by something else Swingy on the AWT EDT so will be okay, until a gnat sneezes.) – Tom Hawtin - tackline Jan 16 '13 at 02:50

0 Answers0