Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6333261

Addition to JDialog documentation on setLayout

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The target parameter of the BoxLayout constructor is confusing due to the rerouting of the setLayout method to the ContentPane.
      Let me be more specific:

      The following code is working:
      JPanel panel=new JPanel();
      panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS)

      One might expect that the following should work too:
      JDialog dialog=new JDialog();
      dialog.setLayout(new BoxLayout(dialog,BoxLayout.PAGE_AXIS)

      But it ain't: it gives a fuzzy runtime error telling the BoxLayout can't be shared. This is caused by the fact that the target of the BoxLayout isn't the dialog itself.
      The following code is working:
      JDialog dialog=new JDialog();
      dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.PAGE_AXIS)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A remark stating the pitfall
      ACTUAL -
      A reference to ContentPane which is no real help at all.

      URL OF FAULTY DOCUMENTATION :
      http://java.sun.com/j2se/1.5.0/docs/api/index.html?javax/swing/BoxLayout.html

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: