0

I'm having trouble getting the buttons on a simple Scala MainFrame GUI to align at center. Have tried many combos of buttonname.peer.setAlignmentX and Y with no effect.

The code is listed below:

object CGui extends SimpleSwingApplication 
   {
     def top = new MainFrame 
      {
        title = "Client Dashboard"
        var tbox    = new TextArea(4,20) { text = "Welcome to the dashboard"}
        val stats_button = new Button    { text = " View Statistics    " }
        val sp_button = new Button       { text = " Add Server Process " }
        val cp_button = new Button       { text = " Add Local Process  " } 
        val conn_button = new Button     { text = " Connect" } 
        val quit_button = new Button     { text = " Quit" }
  // GUI Components *************************************************End   *****
  // GUI SetUp ******************************************************Start *****
        contents = new BoxPanel(Orientation.Vertical) 
         {
           contents += new Label("            ")
           contents += tbox
           contents += new Label("            ")
           contents += stats_button
           contents += new Label("            ")
           contents += sp_button
           contents += new Label("            ")
           contents += cp_button
           contents += new Label("            ")
           contents += new FlowPanel {
           contents += new Label("            ")
           contents += conn_button
           contents += quit_button }
           border = Swing.EmptyBorder(20, 20, 20, 20)
         }
        listenTo(sp_button, cp_button, stats_button, conn_button, quit_button)
  // GUI SetUp ******************************************************End   ***** 

Can anyone point me to any descriptions of setAlignmentX,Y usage. Would ScalaDoc have examples of usage ?

1 Answers1

0

After investigating the post Scala Swing Component alignment, I was able to use BorderPanel { } to position the buttons as in the code below:

// GUI SetUp ******************************************************Start *****
        contents = new BoxPanel(Orientation.Vertical) 
         {
           contents += new Label("            ")
           contents += tbox
           contents += new Label("            ")
           contents += new BorderPanel {
            add(stats_button, BorderPanel.Position.Center)}
           contents += new Label("            ")
           contents += new BorderPanel {
            add(sp_button, BorderPanel.Position.Center)}
           contents += new Label("            ")
           contents += new BorderPanel {
            add(cp_button, BorderPanel.Position.Center)}
           contents += new Label("            ")
           contents += new FlowPanel 
           {
            contents += new BorderPanel {
            add(conn_button, BorderPanel.Position.West)
            add(quit_button, BorderPanel.Position.Center) }
           }

           border = Swing.EmptyBorder(20, 20, 20, 20)
         }
        listenTo(sp_button, cp_button, stats_button, conn_button, quit_button)
  // GUI SetUp ******************************************************End   ***** 

Should have looked at it before posting mine.