2

I am using GroupLayout for my main layout, and baseline alignment works fine, until I add internal panels. It seems the baseline is not propagated through these panels: While all buttons, labels, etc. directly added to the panel with GroupLayout are properly aligned with respect to their baseline, the components inside the inner panels are not.

Since Scala Swing surprisingly doesn't have a GroupPanel, I am using the one from Andreas Flierl, but that shouldn't be important, as I am sure it's an issue of the underlying swing classes and how to condition them.

import swing._
import eu.flierl.grouppanel.GroupPanel

val f = new Frame {
  contents = new GroupPanel {
    val but = new Button { text = "button" }
    val lb  = new Label  { text = "label"  }
    val inner = new FlowPanel {
       contents += new Button { text = "ibut" }
       contents += new Label  { text = "ilab" }
    }
    theHorizontalLayout is Sequential        (but, lb, inner)
    theVerticalLayout   is Parallel(Baseline)(but, lb, inner)
  }
  centerOnScreen()
  pack()
  open()
}

Note in the screenshot, how the inner panel is aligned with the bottom and not baseline. This problem is independent of the layout manager used for the child panel (it could be another group layout).

screenshot

0__
  • 66,707
  • 21
  • 171
  • 266

1 Answers1

0

It seems, getBaseline of the underlying peer must be overridden. Too bad there is no hook for that in Scala Swing (perhaps because it would make it rely on Java 1.6?)

val f = new Frame {
  contents = new GroupPanel {
    val but = new Button { text = "button" }
    val lb  = new Label  { text = "label"  }
    val inner = new FlowPanel {
      val b = new Button { text = "ibut" } 
      override lazy val peer: javax.swing.JPanel =
        new javax.swing.JPanel(new java.awt.FlowLayout(1)) with SuperMixin {
          override def getBaseline(w: Int, h: Int): Int =
            b.peer.getBaseline(w, h) + getInsets().top
        }
      // vGap = 0
      contents += b
      contents += new Label { text = "ilab" }
    }
    theHorizontalLayout is Sequential(but, lb, inner)
    theVerticalLayout is Parallel(Baseline)(but, lb, inner)
  }
  centerOnScreen()
  pack()
  open()
}
0__
  • 66,707
  • 21
  • 171
  • 266